Results 1 to 5 of 5

Thread: QwtPlotCurve/QwtPlotIntervalCurve and auto scale

  1. #1
    Join Date
    Oct 2019
    Posts
    8
    Qt products
    Qt5
    Platforms
    Windows

    Default QwtPlotCurve/QwtPlotIntervalCurve and auto scale

    Consider the following code:

    Qt Code:
    1. // Generate data
    2. QVector<QPointF> points{ QPointF(0, 25), QPointF(10, 12), QPointF(20, 20), QPointF(30, 31), QPointF(40, 20), QPointF(50, 15) };
    3. QVector<QwtIntervalSample> intervalData{ QwtIntervalSample(0, 22, 28), QwtIntervalSample(10, 9, 15), QwtIntervalSample(20, 18, 22),
    4. QwtIntervalSample(30, 29, 33), QwtIntervalSample(40, 15, 25), QwtIntervalSample(50, 9, 21) };
    5.  
    6. // Create curve
    7. auto curve = new QwtPlotCurve();
    8. curve->setSamples(points);
    9. curve->setSymbol(new QwtSymbol(QwtSymbol::Ellipse, QBrush(Qt::darkGreen), QPen(Qt::green), QSize(10, 10)));
    10. curve->setPen(QPen(Qt::darkGreen));
    11. curve->attach(m_plot);
    12.  
    13. // Create interval curve
    14. auto errorCurve = new QwtPlotIntervalCurve();
    15. errorCurve->setSamples(intervalData);
    16. errorCurve->setStyle(QwtPlotIntervalCurve::NoCurve);
    17. QwtIntervalSymbol* errorBar = new QwtIntervalSymbol(QwtIntervalSymbol::Bar);
    18. errorBar->setWidth(8);
    19. errorBar->setPen(QPen(Qt::black));
    20. errorCurve->setSymbol(errorBar);
    21. errorCurve->setRenderHint(QwtPlotItem::RenderAntialiased, false);
    22. errorCurve->attach(m_plot);
    23.  
    24. // Apply auto scale
    25. m_plot->setAxisAutoScale(QwtPlot::xBottom, true);
    26. m_plot->setAxisAutoScale(QwtPlot::yLeft, true);
    27. m_plot->replot();
    To copy to clipboard, switch view to plain text mode 

    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?
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,065
    Thanks
    286
    Thanked 831 Times in 818 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default 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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Oct 2019
    Posts
    8
    Qt products
    Qt5
    Platforms
    Windows

    Default 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.

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

    Default Re: QwtPlotCurve/QwtPlotIntervalCurve and auto scale


  5. #5
    Join Date
    Oct 2019
    Posts
    8
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QwtPlotCurve/QwtPlotIntervalCurve and auto scale

    Quote Originally Posted by Uwe View Post
    Ah, thank you, Uwe. So it is the Floating attribute that I did not set.

Similar Threads

  1. Replies: 1
    Last Post: 9th September 2013, 08:50
  2. Auto scale with margin
    By mqt in forum Qwt
    Replies: 4
    Last Post: 12th August 2013, 09:40
  3. Axis Auto Scale
    By gkarthick5 in forum Qwt
    Replies: 3
    Last Post: 13th July 2011, 14:57
  4. Auto scale a QGraphicsView
    By niluje in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2011, 00:43
  5. 4 axis auto scale..
    By Vincenzo in forum Qwt
    Replies: 0
    Last Post: 22nd March 2009, 02:12

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.