Results 1 to 7 of 7

Thread: QwtPlotZoomer not to change the yAxis scale

  1. #1
    Join Date
    Dec 2012
    Posts
    8
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QwtPlotZoomer not to change the yAxis scale

    Hello!
    I'm using ScrollZoomer class from realtime example. I wanted to zoom in and out by pushbuttons, so I made something like:
    Qt Code:
    1. QRectF rectangle = m_zoomer->zoomStack().top();
    2. rectangle.adjust(rectangle.width() * 0.1, 0, -(rectangle.width() * 0.1), 0);
    3. m_zoomer->zoom(rectangle);
    To copy to clipboard, switch view to plain text mode 

    I only want to zoom in x-direction, so the yAxis to stay untouched. This happens to work fine, but the problem comes up when I try to set yAxis to solid minimum and maximum. I call
    Qt Code:
    1. setAxisScale()
    To copy to clipboard, switch view to plain text mode 
    with good parameters after I attach curves and it looks ok at the first glance. But after hitting any "zoom" button the plot is rescaled and yAxis scale changes. I tried to call setAxisAutoScale(false) for yAxis in the plot constructor, but this makes that after I hit a zoom button, yAxis scale seems to be reseted to min: 0, max: 1000 :/.
    It seems like it's a minor problem, but only when one knows where to look for - any ideas?
    Thanks in advance

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

    Default Re: QwtPlotZoomer not to change the yAxis scale

    Forget QwtPlotZoomer - it has nothing to do with your situation. All you need to do is to implement slots for zoom in/out that calculate a new scale from the current scale ranges and to assign them with QwtPlot::setAxisScale() ( or QwtPlot::setAxisScaleDiv(), when you need to control the ticks in detail ).

    Have a look at the implementation of QwtPlotMagnifier::rescale(), what should be pretty close to the code you need in your slots.

    Uwe

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

    dontgonearthecastle (7th January 2013)

  4. #3
    Join Date
    Dec 2012
    Posts
    8
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QwtPlotZoomer not to change the yAxis scale

    Heh, I've overridden the zoom slots in my ScrollZoomer class to be like this:
    Qt Code:
    1. void ScrollZoomer::zoom(const QRectF &rect)
    2. {
    3. QwtPlot *plt = plot();
    4. QwtScaleDiv *div = plt->axisScaleDiv(QwtPlot::yLeft);
    5. plt->setAxisScale(QwtPlot::yLeft, div->lowerBound(), div->upperBound());
    6. plt->replot();
    7. QwtPlotZoomer::zoom(rect);
    8. }
    To copy to clipboard, switch view to plain text mode 
    (with zoom(int up) being exactly the same - of course with proper zoom slot called at the end)
    and to be honest, I have no idea why, but it works fine! Unfortunately, replotting slows the whole thing down with bigger plots, but I guess there's no easy way out of it now
    Thanks

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

    Default Re: QwtPlotZoomer not to change the yAxis scale

    QwtPlotZoomer::zoom( rect ) also sets the scale and does a replot - so your code above has no effect beside that it slows down the operation significantly. Why don't you listen to me: QwtPlotZoomer has nothing to do with your use case.

    Instead this is your code:

    Qt Code:
    1. void zoomAxis( QwtPlot* plot, int axis, double factor )
    2. {
    3. const QwtScaleDiv &scaleDiv = plot->axisScaleDiv( axis );
    4.  
    5. const double center =
    6. scaleDiv.lowerBound() + scaleDiv.range() / 2;
    7. const double width_2 = scaleDiv.range() / 2 * factor;
    8.  
    9. plot->setAxisScale( axis, center - width_2, center + width_2 );
    10. plot->replot();
    11. }
    To copy to clipboard, switch view to plain text mode 

    When you want to zoom in/out more than one axis don't use the code above unmodified and take care that the replot is done only once.

    Uwe

  6. #5
    Join Date
    Dec 2012
    Posts
    8
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QwtPlotZoomer not to change the yAxis scale

    Hmm, I don't understand it still :/
    As far as I know, code you suggest actually zooms the view - it's fine, but the problem is that scrollbars stay untouched. I guess this is why I stick to ScrollZoomer::zoom (being QwtPlotZoomer::zoom I guess) - it happens to manage scrollbars and other things fine. I don't know if I'm right, but with my code from the opening post I wanted just to feed the "nice working ScrollZoomer from realtime example" with the right zooming rectangle. That would leave me with ScrollZoomer code untouched because it's working fine for me. As far as I understand, your approach, Uwe, is a little bit different, right? I just thought it's going to work, when I get the idea when is the yLeft axis rescaled - I would stop it from rescaling and it will be it. Problem is: is that even possible?
    Thank you for your patience anyways

  7. #6
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QwtPlotZoomer not to change the yAxis scale

    O.k. I missed that you are interested in the scroll bars - so back to your initial posting: 0.0 -> 1000.0 are the initial settings of a plot axis. Looks like the zoomBase of the zoomer is initialized with these values, what usually happens, when the zoomer gets initialized too to early.

    You have 2 options:


    1. attach the items ( that have an effect for autoscaling ) first
    2. use QwtPlotZoomer::setZoomBase()


    Uwe

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

    dontgonearthecastle (14th January 2013)

  9. #7
    Join Date
    Dec 2012
    Posts
    8
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QwtPlotZoomer not to change the yAxis scale

    Hah, should have known it was this easy
    I moved setZoomBase line to be AFTER setting the axes scales (hmm... seems legit, right? ). Now it's great!
    Thank you very much, Uwe

Similar Threads

  1. Change mouse bindings for qwtplotzoomer
    By ivareske in forum Qwt
    Replies: 5
    Last Post: 22nd January 2019, 09:27
  2. Replies: 2
    Last Post: 23rd May 2011, 09:01
  3. Replies: 1
    Last Post: 13th May 2011, 18:12
  4. change manually the scale of y-axis
    By fatecasino in forum Qwt
    Replies: 2
    Last Post: 14th February 2011, 20:24
  5. Access and change labels on the X-scale
    By Tottish in forum Qwt
    Replies: 0
    Last Post: 26th October 2010, 16:42

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.