PDA

View Full Version : Scaling and zooming with logarithmic scales



Benoît Hubert
3rd September 2008, 11:08
The application I'm working on uses Qwt to display curves. It lets the user choose between linear and logarithmic scales, for each of the plot axes.

I have a problem related to zooming and scaling, when I use the logarithmic scale.

When I don't zoom on a curve, Qwt does auto-scaling for the plot. On an axis with log scale, any negative or null value is considered invalid. So I sub-classed QwtPlotCurve and redefined boundingRect() and draw() in the child class, so that only valid points are drawn and taken into account to define the curve's bounding rectangle. This works fine, and prevents Qwt from setting the log axis' inferior boundary to 1e-100.

I still have a problem with zooming. When my plot is drawn for the first time, the axes are correctly set thanks to auto-scaling. If I zoom in, it's still ok, but if I zoom out just after, the axes' boundaries take wrong values (for axes with log scale). For example, the inferior boundary is set to 1e-100, which makes all the plot look "flattened" (the inferior boundary should be set to 0.001).

I have a hint : Qwt uses a stack of rectangles to handle zooming. When a plot is first set up and we attach a QwtPlotZoomer to it, and call setZoomBase() on it, a rectangle is pushed to the zoom stack, on index 0. The value of this rectangle seems to be computed regardless of the scale type (linear or log).
From what I've observed, it seems like the inferior boundaries for this rectangle are (x=0.0, y=0.0). So when I zoom out totally and this rectangle is "popped" from the stack, 0.0 on log scale is translated to "minus infinity", that is, 1e-100, which become the inferior boundary.

How to tell Qwt to take into account the plot's bounding rectangle when I set up the zoomer, so that it scales correctly when I zoom out ? Thanks for advice.

Uwe
11th September 2008, 09:17
I have a hint : Qwt uses a stack of rectangles to handle zooming. When a plot is first set up and we attach a QwtPlotZoomer to it, and call setZoomBase() on it, a rectangle is pushed to the zoom stack, on index 0. The value of this rectangle seems to be computed regardless of the scale type (linear or log).
Nothing is computed: it simply stores the min/max values of the corresponding scales as they are.

From what I've observed, it seems like the inferior boundaries for this rectangle are (x=0.0, y=0.0).
Then these are the inferior boundaries of the scales.

I guess you are calling QwtPlotZoomer::setZoomBase too early - before your scales are initialized properly.

Uwe