PDA

View Full Version : how to get axis range when autoscale is on?



hind
16th June 2013, 11:07
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?

Uwe
16th June 2013, 13:33
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

hind
17th June 2013, 03:23
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.

Uwe
17th June 2013, 06:56
Are you reinventing a QwtPlotMarker::HLine marker ?

Uwe

hind
1st July 2013, 04:03
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!


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!

Uwe
4th July 2013, 07:24
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