Results 1 to 5 of 5

Thread: QwtPlotCurve/QwtPlotIntervalCurve and auto scale

Threaded View

Previous Post Previous Post   Next Post Next Post
  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

Similar Threads

  1. Replies: 1
    Last Post: 9th September 2013, 07:50
  2. Auto scale with margin
    By mqt in forum Qwt
    Replies: 4
    Last Post: 12th August 2013, 08:40
  3. Axis Auto Scale
    By gkarthick5 in forum Qwt
    Replies: 3
    Last Post: 13th July 2011, 13:57
  4. Auto scale a QGraphicsView
    By niluje in forum Qt Programming
    Replies: 4
    Last Post: 5th July 2011, 23:43
  5. 4 axis auto scale..
    By Vincenzo in forum Qwt
    Replies: 0
    Last Post: 22nd March 2009, 01: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.