1 Attachment(s)
QwtPlotCurve/QwtPlotIntervalCurve and auto scale
Consider the following code:
Code:
// Generate data
QVector<QPointF> points
{ QPointF(0,
25),
QPointF(10,
12),
QPointF(20,
20),
QPointF(30,
31),
QPointF(40,
20),
QPointF(50,
15) };
QVector<QwtIntervalSample> intervalData{ QwtIntervalSample(0, 22, 28), QwtIntervalSample(10, 9, 15), QwtIntervalSample(20, 18, 22),
QwtIntervalSample(30, 29, 33), QwtIntervalSample(40, 15, 25), QwtIntervalSample(50, 9, 21) };
// Create curve
curve->setSamples(points);
curve
->setPen
(QPen(Qt
::darkGreen));
curve->attach(m_plot);
// Create interval curve
auto errorCurve = new QwtPlotIntervalCurve();
errorCurve->setSamples(intervalData);
errorCurve->setStyle(QwtPlotIntervalCurve::NoCurve);
QwtIntervalSymbol* errorBar = new QwtIntervalSymbol(QwtIntervalSymbol::Bar);
errorBar->setWidth(8);
errorBar
->setPen
(QPen(Qt
::black));
errorCurve->setSymbol(errorBar);
errorCurve
->setRenderHint
(QwtPlotItem::RenderAntialiased,
false);
errorCurve->attach(m_plot);
// Apply auto scale
m_plot
->setAxisAutoScale
(QwtPlot::xBottom,
true);
m_plot
->setAxisAutoScale
(QwtPlot::yLeft,
true);
m_plot->replot();
When you run that code and look at the plot you will see that the y axis's scaling is not correct. Or at least it is not what I expect it to be. The lower end is set to 5 and the upper end is set to 35, but the minimum of the data is 9 and the maximum is 33. It seems as if the axes try to set their minimum and maximum to "nice" values instead of the real minimum and maximum values of the data.
If I comment the line errorCurve->attach(m_plot) and show the data curve only, the effect is the same. The y axis auto scales to the "nice" values of 10/35 instead of the real values 12/31.
Is this some setting for the auto scale that I am missing or is this a bug?
Re: QwtPlotCurve/QwtPlotIntervalCurve and auto scale
I believe that Qwt uses an algorithm that was developed a long time ago for computing "nice" axis divisions. These are usually multiples of 1, 2, 5, 10, etc. that result in tick marks having integer or other "nice" values, instead of things like 4.01569 and 5.10268, with a spacing of 1.08699 which could occur if you used the actual plot data and a fixed number of ticks.
Qwt has classes that allow you to install your own axis scale calculator (I don't use Qwt 6, so I don't know what these classes are called now) so you can specify anything you want for axis spacing and tick labeling if you don't like the default implementation.
Re: QwtPlotCurve/QwtPlotIntervalCurve and auto scale
The problem is not the tick marks, they are fine as they are. The problem is the auto scale and how the displayed minimum and maximum of the axes are calculated. If I call setAxisScale I can set them manually to any value that I want, so I was wondering if the "nice" numbers that are set by auto scale are intended or a bug. And if it is intended if there is any setting/configuration where I can change or influence this behaviour.
Re: QwtPlotCurve/QwtPlotIntervalCurve and auto scale
Re: QwtPlotCurve/QwtPlotIntervalCurve and auto scale
Quote:
Originally Posted by
Uwe
Ah, thank you, Uwe. So it is the Floating attribute that I did not set.