Results 1 to 6 of 6

Thread: Show a scale for the same axis on both sides of the plotcanvas

  1. #1
    Join Date
    Jun 2009
    Posts
    9
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Show a scale for the same axis on both sides of the plotcanvas

    Hi There,

    I would like to show a scale for the y Axis on the left as well as the right side of the plot canvas. They should display exactly the same range etc.

    I guess I could add a QwtScaleWidget and work out something with this, but then I guess I have to do the layout stuff myself?

    Thanks a lot
    Simon

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,253
    Thanked 860 Times in 809 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Show a scale for the same axis on both sides of the plotcanvas

    I would like to show a scale for the y Axis on the left as well as the right side of the plot canvas.
    plot->enableAxis( QwtPlot::yRight );

    They should display exactly the same range etc.
    This depends on how you set your QwtPlot::Left axis.

    If you don't assign it manually you can connect to the QwtScaleWidget::scaleDivChanged() signal and synchronize the right axis from the left one ( use QwtPlot::setAxisScaleDiv() ).

    Uwe

  3. The following user says thank you to Uwe for this useful post:

    SimonSchmeisser (20th February 2012)

  4. #3
    Join Date
    Jun 2009
    Posts
    9
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Show a scale for the same axis on both sides of the plotcanvas

    ok, I had to set the initial range for yRight as well (I'm doing it manually) and then the following works:

    Qt Code:
    1. connect(axisWidget(yLeft), SIGNAL(scaleDivChanged()), this, SLOT(updateRightScale()));
    2. updateRightScale();
    3. connect(axisWidget(xBottom), SIGNAL(scaleDivChanged()), this, SLOT(updateTopScale()));
    4. updateTopScale();
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void Plot::updateRightScale() {
    2. axisWidget(yRight)->setScaleDiv(axisScaleEngine(yLeft)->transformation(), *axisScaleDiv(yLeft));
    3. }
    4.  
    5. void Plot::updateTopScale() {
    6. axisWidget(xTop)->setScaleDiv(axisScaleEngine(xBottom)->transformation(), *axisScaleDiv(xBottom));
    7. }
    To copy to clipboard, switch view to plain text mode 

    thanks! I was just thinking there might be a way to tell the PlotScaleWidget(yRight) to get its actuall data directly from yLeft.
    Simon


    Added after 23 minutes:


    hmm, that's still not working perfectly. I have two problems:

    1. when I use QwtPlotZoomer, left and right axis get out of sync

    2. I have some code that does not actually display the plot, but just writes it to an image file. There xBottom and yTop are out of sync. The code is quite simple:
    Qt Code:
    1. Plot plot;
    2. plot.setTitle(m_iqeCurveName);
    3. QFont axisFont = plot.axisFont(QwtPlot::xBottom);
    4. axisFont.setPointSize(14);
    5. axisFont.setBold(true);
    6. plot.setAxisFont(QwtPlot::xBottom, axisFont);
    7. plot.setAxisFont(QwtPlot::yLeft, axisFont);
    8.  
    9. PlotCurve rMeasCurve;
    10. rMeasCurve.update(m_R_meas);
    11. rMeasCurve.setEnabled(true);
    12. rMeasCurve.setPlot(&plot);
    13. rMeasCurve.setName("R_meas");
    14. rMeasCurve.setColor(Qt::green);
    15. rMeasCurve.setSymbol(QwtSymbol::NoSymbol);
    16. rMeasCurve.setLineWidth(2);
    17.  
    18. plot.setDefaultRange(250, 1200, 0, 1.1);
    19. plot.replot();
    20.  
    21. plot.saveImage(outputDir.absoluteFilePath("R/R "+ ID + ".png"));
    To copy to clipboard, switch view to plain text mode 

    with the following for setDefaultRange:
    Qt Code:
    1. void Plot::setDefaultRange(double minX, double maxX, double minY, double maxY) {
    2. setAxisScale(QwtPlot::xBottom, minX, maxX);
    3. setAxisScale(QwtPlot::xTop, minX, maxX);
    4. setAxisScale(QwtPlot::yLeft, minY, maxY);
    5. setAxisScale(QwtPlot::yRight, minY, maxY);
    6.  
    7. replot();
    8.  
    9. m_zoomer->setZoomBase(false); // setzt den aktuellen Zoom als Standard?
    10. }
    To copy to clipboard, switch view to plain text mode 

    Any ideas?
    Last edited by SimonSchmeisser; 20th February 2012 at 13:53.

  5. #4
    Join Date
    Jun 2009
    Posts
    9
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Show a scale for the same axis on both sides of the plotcanvas

    Problem #1 can be solved like this:

    Qt Code:
    1. connect(m_zoomer, SIGNAL(zoomed(QRectF)), this, SLOT(updateSecondaryAxis(QRectF)));
    2.  
    3. void Plot::updateSecondaryAxis(const QRectF &zoomRect) {
    4. setAxisScale(QwtPlot::xTop, zoomRect.left(), zoomRect.right());
    5. setAxisScale(QwtPlot::yRight, zoomRect.top(), zoomRect.bottom());
    6.  
    7. replot();
    8. }
    To copy to clipboard, switch view to plain text mode 

    Problem #2 disappears when I enable Labels at the secondary Axes, so I might go this way for the moment. It appears to be a bug though.

  6. #5
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,253
    Thanked 860 Times in 809 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Show a scale for the same axis on both sides of the plotcanvas

    Quote Originally Posted by SimonSchmeisser View Post
    Qt Code:
    1. void Plot::updateRightScale() {
    2. axisWidget(yRight)->setScaleDiv(axisScaleEngine(yLeft)->transformation(), *axisScaleDiv(yLeft));
    3. }
    To copy to clipboard, switch view to plain text mode 
    It has to look like this:
    Qt Code:
    1. void Plot::updateRightScale() {
    2. setAxisScaleDiv( yLeft, *axisScaleDiv(yLeft));
    3. }
    To copy to clipboard, switch view to plain text mode 
    There is another QwtScaleDiv object for each axis - stored in the plot widget - that kills your assigned values next time replot is called ( see the implementation of QwtPlot::updateAxes() ).

    But the problem with the code above is when to call replot ( to recalculate the layout ) without calling it more than once.

    Uwe

  7. The following user says thank you to Uwe for this useful post:

    SimonSchmeisser (24th February 2012)

  8. #6
    Join Date
    Jun 2009
    Posts
    9
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Show a scale for the same axis on both sides of the plotcanvas

    Problem #1 is indeed solved when I use your variant.

    Problem #2 however remains. When I disable the labels, the xTop scale is stretched in comparison to the xBottom scale. I have "solved" it by setting the label text color to white. Apparently the width of the text is used for calculating the size of the scale, so that it changes between enabled and disabled labels

    Have a nice weekend
    Simon

Similar Threads

  1. qwt axis scale
    By Markus_AC in forum Qwt
    Replies: 0
    Last Post: 15th December 2011, 10:45
  2. Date Scale for X-Axis
    By mishani99 in forum Qwt
    Replies: 3
    Last Post: 6th September 2011, 12:40
  3. Axis Auto Scale
    By gkarthick5 in forum Qwt
    Replies: 3
    Last Post: 13th July 2011, 14:57
  4. Replies: 4
    Last Post: 16th January 2011, 11:32
  5. qwp plot axis scale
    By Cal in forum Qwt
    Replies: 1
    Last Post: 11th May 2009, 18:10

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.