3

I'm trying to plot some data using qt 4.8 and qwt 6, but my curves doesn't scales over plot (1).

This is how I attach curves to plot:

curves[moduleIndex][channelIndex]->setSamples(samples, data);
curves[moduleIndex][channelIndex]->attach(plots[moduleIndex][channelIndex]);

samples and data is QVectors and samples.size() is equal to data.size()

plots[moduleIndex][channelIndex]->axisAutoScale(QwtPlot::xBottom) returns true, so autoScale is enabled.

So am I missing something?

qwt plot auto scale

UPDATE: I thought that the problem occures because disabled axis

plots[i][j]->enableAxis(QwtPlot::yLeft, false);
plots[i][j]->enableAxis(QwtPlot::xBottom, false);

But I've commented it out and it didn't help.

qwt plot auto scale with axis

Stepan Kuzmin
  • 1,031
  • 2
  • 11
  • 21
  • 2
    This is actually how it works. It's trying to put a nice rounded number at the end of the scale. When I encountered same problem I just disabled autoscaling for x axis and set it manually with 'setAxisScale'. Or you may try to do something with QwtScaleEngine class, maybe implement your own... – HeyYO Feb 04 '13 at 12:42

2 Answers2

4

I believe 'autoscale' is alreadyworking. But to make axis look nice, it takes a rounded number for maximum which is causing a gap at the end. Scales of QwtPlot are managed by QwtScaleEngine. You can get a pointer to default scaleEngine your plot using with QwtPlot::axisScaleEngine(...). Setting Floating attribute to true will remove this gap and will fit your data to boundaries. See docs: http://qwt.sourceforge.net/class_qwt_scale_engine.html

Ex:

plot.axisScaleEngine(QwtPlot::xBottom)->setAttribute(QwtScaleEngine::Floating,true);
HeyYO
  • 1,989
  • 17
  • 24
  • Please add some explanatory text to make this a more useful answer. – Paul R Feb 04 '13 at 13:12
  • Mentioned documentation of `QwtScaleEngine` also says that when `Floating` attribute is set, the distance between max/min and borders can be set with [`setMargins()`](http://qwt.sourceforge.net/class_qwt_scale_engine.html#aed2ab1fc105a25fa97bbecf4b2f541a7). So if after setting this attribute the gap is still to big, it can be decreased with this setter. – NIA Feb 04 '13 at 15:13
  • I tried this with a data changing from 0 to 1019 (both x and y). If I don't set anything; the scale is set to 'from 0 to 1200'. When I set floating attribute to true, gap disappears and data is fitted to axis. So it works for me. But what I understand from setMargins() is; it sets the minimum gap. Because if I call setMargins(100,0) for xAxis, a gap appears on the left.. Can you tell me how did you test this? – HeyYO Feb 04 '13 at 19:36
  • Read my hint above. The scale engine is responsible for calculating the scale. The gap between the end of the scales and the borders of the canvas are because of the plot layout. See the API of QqwtPlotLayout if you want to modify it. – Uwe Feb 04 '13 at 19:53
4

When setting QwtScaleEngine::Floating + QwtPlotLayout::setAlignCanvasToScales( true ) the canvas should be perfectly aligned to the boundaries of your curve.

Uwe
  • 705
  • 3
  • 3