Results 1 to 6 of 6

Thread: how to get axis range when autoscale is on?

  1. #1
    Join Date
    Mar 2013
    Posts
    28
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Question how to get axis range when autoscale is on?

    When I create a new QwtPlot the autoscale is on by default and it works just fine. But how does my program know the lower bound and upper bound of the axis (for some reason)? It can't read from the screen like me. I tried the QwtScaleDiv but no luck, it always returns 0 and 1000, which is the default value for manual scaling I guess. When I set the autoscale to false it returns those two values too.
    Do I have to calculate the bounds myself anyway?

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

    Default Re: how to get axis range when autoscale is on?

    QwtPlot::axisScaleDiv() returns the range of the scale, but as the scale division is calculated in the replot operation you probably tried too early. You can force a recalculation of the scales by calling QwtPlot::updateAxes() - but doing so is usually an indication of doing something wrong.


    • You can connect to the QwtScaleWidget::scaleDivChanged() signal when you need to know when a scale is changing.
    • Also be aware of the QwtPlotItem::ScaleInterest flag, that can be enabled for a plot item that needs to be adjusted to the scale ( like for example the grid ).
    • Another hook is QwtSeriesData::setRectOfInterest().


    But without knowing your use case I can't tell what API is the best one for you.

    Uwe

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

    hind (17th June 2013)

  4. #3
    Join Date
    Mar 2013
    Posts
    28
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to get axis range when autoscale is on?

    Thank you very much!
    I'm plotting a scatter diagram with a regression line. I just want to make the line fit the chart so I made a curve with two points taking the lower and upper bounds as the x coordinates.
    Now it's solved when I get the range of xbottem after a replot and set the line and replot agian...
    QwtPlotItem::ScaleInterest flag seems to make sense to me but I failed to find it.
    QwtSeriesData::setRectOfInterest() may also do the trick when I understand it after some test.

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

    Default Re: how to get axis range when autoscale is on?

    Are you reinventing a QwtPlotMarker::HLine marker ?

    Uwe

  6. #5
    Join Date
    Mar 2013
    Posts
    28
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to get axis range when autoscale is on?

    Quote Originally Posted by Uwe View Post
    Are you reinventing a QwtPlotMarker::HLine marker ?

    Uwe
    Sorry but I didn't think I need a QwtPlotMarker::HLine marker because the regression line I was drawing could have any slope. I checked the doc of QwtPlotMarker again but found no useful info on this. Tell me if I missed something. Thanks again!

    Quote Originally Posted by Uwe View Post
    Are you reinventing a QwtPlotMarker::HLine marker ?

    Uwe
    Sorry but I didn't think I need a QwtPlotMarker::HLine marker because the regression line I was drawing could have any slope. I checked the doc of QwtPlotMarker again but found no useful info on this. Tell me if I missed something. Thanks again!

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

    Default Re: how to get axis range when autoscale is on?

    Well, how is your regression line defined: y = m * x + t ?

    For such a thing I would implement my own plot item. In its draw method you know the geometry of the canvas and using QLineF you can easily calculate the cutting points of the line with the canvas borders.
    The rescaler example shows a plot item that draws a rectangle ( only an example, with QwtPlotShapeItem this could be done as well ). Your plot item will - of course - be different, but not more difficult.

    Uwe

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

    hind (4th July 2013)

Similar Threads

  1. Disabling autoscale is not wirking
    By P@u1 in forum Qwt
    Replies: 2
    Last Post: 27th July 2011, 10:25
  2. Replies: 2
    Last Post: 8th July 2011, 01:06
  3. axis autoscale: 2 user case scenarios
    By fatecasino in forum Qwt
    Replies: 1
    Last Post: 19th January 2011, 03:11
  4. autoScale doesn't work
    By Braunstein in forum Qwt
    Replies: 4
    Last Post: 12th November 2010, 19:22
  5. Replies: 1
    Last Post: 21st April 2010, 03:54

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.