Results 1 to 13 of 13

Thread: PyQT QwtScaleDiv adds ticks to axis

  1. #1
    Join Date
    Mar 2011
    Posts
    11
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default PyQT QwtScaleDiv adds ticks to axis

    Hi, i'm implementing my own QwtScaleDraw like that:
    Qt Code:
    1. class TimeScaleDraw(QwtScaleDraw):
    2. def __init__(self, baseTime):
    3. QwtScaleDraw.__init__(self)
    4. #QTime baseTime
    5. self.baseTime = baseTime
    6. self.setLabelAlignment(Qt.AlignLeft | Qt.AlignBottom)
    7. self.setLabelRotation(-25.0)
    8.  
    9. def label(self, secs):
    10. upTime = self.baseTime.addSecs(secs)
    11. upTime = upTime.toString('dd MM yy hh:mm:ss')
    12. return QwtText(upTime)
    To copy to clipboard, switch view to plain text mode 
    then I use it this way:
    Qt Code:
    1. ticks = [0, 60, 120]
    2. div = QwtScaleDiv()
    3. div.setInterval(ticks[0], ticks[len(ticks)-1])
    4. div.setTicks(QwtScaleDiv.MinorTick, [])
    5. div.setTicks(QwtScaleDiv.MediumTick, [])
    6. div.setTicks(QwtScaleDiv.MajorTick, ticks)
    7. draw = TimeScaleDraw(QDateTime(self.main.timeMin))
    8. draw.setScaleDiv(div)
    9. self.plot.setAxisScaleDraw(QwtPlot.xBottom, draw)
    10. self.plot.setAxisScale(QwtPlot.yLeft, self.main.valueMin, self.main.valueMax)
    To copy to clipboard, switch view to plain text mode 
    I'd like to have only 3 ticks (where there actually are values) on my x axis, but some how I get more ticks added (see screen shot). what do i do wrong? any suggestion?
    Attached Images Attached Images
    Last edited by mbernasocchi; 16th March 2011 at 11:59. Reason: updated contents

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: PyQT QwtScaleDiv adds ticks to axis

    Use QwtPlot::setAxisScaleDiv() - the ticks directly assigned to your scaleDraw object will be overwritten by the next replot.

    Uwe

  3. #3
    Join Date
    Mar 2011
    Posts
    11
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: PyQT QwtScaleDiv adds ticks to axis

    Hi Uwe, thanks for the reply, I had tryed it already and the result was worse, but I tryed it again just to be shure. it does not work (see attach).
    my code is:
    Qt Code:
    1. ticks = [0, 60, 120]
    2. div = QwtScaleDiv()
    3. div.setInterval(ticks[0], ticks[len(ticks)-1])
    4. div.setTicks(QwtScaleDiv.MinorTick, [])
    5. div.setTicks(QwtScaleDiv.MediumTick, [])
    6. div.setTicks(QwtScaleDiv.MajorTick, ticks)
    7. draw = TimeScaleDraw(QDateTime(self.main.timeMin))
    8. #draw.setScaleDiv(div)
    9. self.plot.setAxisScaleDiv(QwtPlot.xBottom, div)
    10. self.plot.setAxisScaleDraw(QwtPlot.xBottom, draw)
    11. self.plot.setAxisScale(QwtPlot.yLeft, self.main.valueMin, self.main.valueMax)
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jul 2010
    Posts
    37
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: PyQT QwtScaleDiv adds ticks to axis

    Hi, did you solved ?
    bye

  5. #5
    Join Date
    Mar 2011
    Posts
    11
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: PyQT QwtScaleDiv adds ticks to axis

    no any ideas?

  6. #6
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: PyQT QwtScaleDiv adds ticks to axis

    What type of answer do you expect for "it does not work" ?

    Uwe

  7. #7
    Join Date
    Mar 2011
    Posts
    11
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: PyQT QwtScaleDiv adds ticks to axis

    Hi Uwe, well the situation for me is that I've the following code:
    Qt Code:
    1. ticks = [0, 60, 120]
    2. div = QwtScaleDiv()
    3. div.setInterval(ticks[0], ticks[len(ticks)-1])
    4. div.setTicks(QwtScaleDiv.MinorTick, [])
    5. div.setTicks(QwtScaleDiv.MediumTick, [])
    6. div.setTicks(QwtScaleDiv.MajorTick, ticks)
    7. draw = TimeScaleDraw(QDateTime(self.main.timeMin))
    8. #draw.setScaleDiv(div)
    9. self.plot.setAxisScaleDiv(QwtPlot.xBottom, div)
    10. self.plot.setAxisScaleDraw(QwtPlot.xBottom, draw)
    11. self.plot.setAxisScale(QwtPlot.yLeft, self.main.valueMin, self.main.valueMax)
    To copy to clipboard, switch view to plain text mode 
    which instead of generating only 3 major ticks at the desired location it creates many more ticks as shown in the attachement in the post above. you can see the full code at http://hub.qgis.org/projects/multivi...eplotwidget.py i'd be super if you could give me an hint...
    thanks a lot
    Marco

  8. #8
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: PyQT QwtScaleDiv adds ticks to axis

    QwtScaleDiv internally has a flag, that indicates if it is valid or not - if not it gets recalculated from the autoscaler. Of course this is a bad class design and has to do with the history of the QwtScaleDiv class.

    Instead you have to initialize your QwtScaleDiv object this way ( C++ ):

    Qt Code:
    1. QList<double> ticks[QwtScaleDiv::NTickTypes];
    2. ticks[QwtScaleDiv::MajorTick] << 0.0 << 60.0 << 120.0;
    3.  
    4. QwtScaleDiv scaleDiv(
    5. ticks[QwtScaleDiv::MajorTick].first(),
    6. ticks[QwtScaleDiv::MajorTick].last(),
    7. ticks );
    8.  
    9. setAxisScaleDiv(QwtPlot::xBottom, scaleDiv);
    To copy to clipboard, switch view to plain text mode 

    Uwe

  9. The following user says thank you to Uwe for this useful post:

    KrecikNH (6th November 2011)

  10. #9
    Join Date
    Mar 2011
    Posts
    11
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: PyQT QwtScaleDiv adds ticks to axis

    Hi Uwe, thanks for the answer, I tried and it almost works, now I just dont' have the labels anymore (the ticks are at the right place). (see screenshot and note that the picker shows the correct value)
    the code I use is:
    Qt Code:
    1. #update axes
    2. div = QwtScaleDiv(ticks[0], ticks[len(ticks)-1], ticks, [],[])
    3. baseTime = QDateTime(self.mainWidget.timeMin)
    4. draw = TimeScaleDraw(baseTime)
    5. self.plot.setAxisScaleDraw(QwtPlot.xBottom, draw)
    6. self.plot.setAxisScaleDiv(QwtPlot.xBottom, div)
    7.  
    8. class TimeScaleDraw(QwtScaleDraw):
    9. def __init__(self, baseTime):
    10. QwtScaleDraw.__init__(self)
    11. #QTime baseTime
    12. self.baseTime = baseTime
    13. self.setLabelAlignment(Qt.AlignLeft | Qt.AlignBottom)
    14. self.setLabelRotation(-25.0)
    15.  
    16. def label(self, secs):
    17. upTime = self.baseTime.addSecs(secs)
    18. upTime = upTime.toString('dd MM yy hh:mm:ss')
    19. return QwtText(upTime)
    To copy to clipboard, switch view to plain text mode 

    as well, using python one has to know this: http://pyqwt.sourceforge.net/doc5/re...t5.QwtScaleDiv
    do you have an idea why this happens?
    Screenshot.jpg
    thanks Marco

  11. #10
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: PyQT QwtScaleDiv adds ticks to axis

    Is your overloaded label method called - and if yes with which values ?

    Uwe

  12. #11
    Join Date
    Mar 2011
    Posts
    11
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: PyQT QwtScaleDiv adds ticks to axis

    Hi uwe, spot on... no it si not called, when I dont use the
    Qt Code:
    1. self.plot.setAxisScaleDiv(QwtPlot.xBottom, div)
    To copy to clipboard, switch view to plain text mode 
    line then it gets called automatically with the correct values. Do I need to call it myself? where?
    ciao Marco


    Added after 40 minutes:


    Uwe, btw, it is not only my overloaded label that doesn't get called, if I remove the label method in my QwtScaleDraw, nothing changes, the labels are not drawn.
    Last edited by mbernasocchi; 13th April 2011 at 10:12.

  13. #12
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: PyQT QwtScaleDiv adds ticks to axis

    labels are painted for major ticks only. I'm not familiar with the Python API, but maybe the ticks you have set are the minor or medium ticks ?

    Uwe

  14. The following user says thank you to Uwe for this useful post:

    mbernasocchi (13th April 2011)

  15. #13
    Join Date
    Mar 2011
    Posts
    11
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: PyQT QwtScaleDiv adds ticks to axis

    Uwe thanks a lot... you do indeeed know your "baby" by heart. i think there is a bug in the python API documentation. by changing:
    Qt Code:
    1. div = QwtScaleDiv(ticks[0], ticks[len(ticks)-1], [], [], ticks)
    To copy to clipboard, switch view to plain text mode 
    to
    Qt Code:
    1. div = QwtScaleDiv(ticks[0], ticks[len(ticks)-1], ticks, [], [])
    To copy to clipboard, switch view to plain text mode 

    it all works although the documentation it says:
    scaleDiv = QwtScaleDiv(
    lower, upper, majorTicks, mediumTicks, minorTicks)
    I'll contact the API author. thanks a lot Again
    ciao Marco
    working.jpg

Similar Threads

  1. Replies: 12
    Last Post: 18th May 2011, 20:40
  2. Replies: 1
    Last Post: 20th April 2011, 16:23
  3. Replies: 0
    Last Post: 9th August 2010, 10:46
  4. Replies: 1
    Last Post: 30th July 2010, 07:23
  5. Replies: 1
    Last Post: 16th March 2010, 15:23

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.