Results 1 to 3 of 3

Thread: Magnify plot vertically while keeping position of baseline constant

  1. #1
    Join Date
    Sep 2010
    Posts
    35
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Magnify plot vertically while keeping position of baseline constant

    Hi,

    I am using a QwtPlotMagnifier object. I disabled the xBottom-axis so that the plot is magnified in the vertical direction only. I set the mouse button to NoButton because I just want to zoom by using the mouse wheel. This is the corresponding code:

    Qt Code:
    1. mag = new QwtPlotMagnifier(par->spectrum_plot->canvas());
    2. mag->setAxisEnabled(QwtPlot::yLeft, true);
    3. mag->setAxisEnabled(QwtPlot::xBottom, false);
    4. mag->setMouseButton(Qt::NoButton);
    To copy to clipboard, switch view to plain text mode 


    Now this is my problem: The plot I want to magnify is a spectrum and I just want to increase the intensity of the signals by using the mouse wheel. But the baseline of my spectrum (y=0) usually is not centered with respect to the range of the y-axis because the signals are mostly positive and everything else was a waste of plot area.

    Therefore, while magnifying, the baseline is gradually moving to the bottom part of the plot and eventually vanishes completely.

    Now my question: Is there a way to magnify the y-axis while the y=0 position is held at the same screen position so that I keep my basline inside my plot?

    Many thanks for any help

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

    Default Re: Magnify plot vertically while keeping position of baseline constant

    Overload QwtPlotMagnifier::rescale(). Looking into into its implementation will help with your code.

    Uwe

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

    mariposa (6th September 2010)

  4. #3
    Join Date
    Sep 2010
    Posts
    35
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Magnify plot vertically while keeping position of baseline constant

    Many thanks for your answer, Uwe. It helped to solve my problem

    Just in case others have the same problem, here is the code for my reimplementation of the QwtPlotMagnifier::rescale function:

    Qt Code:
    1. void Magnifier::rescale(double factor)
    2. {
    3. factor = qwtAbs(factor);
    4. if ( factor == 1.0 || factor == 0.0 )
    5. return;
    6.  
    7. bool doReplot = false;
    8. QwtPlot* plt = plot();
    9.  
    10. const bool autoReplot = plt->autoReplot();
    11. plt->setAutoReplot(false);
    12.  
    13. for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )
    14. {
    15. const QwtScaleDiv *scaleDiv = plt->axisScaleDiv(axisId);
    16. if ( isAxisEnabled(axisId) && scaleDiv->isValid() )
    17. {
    18.  
    19. plt->setAxisScale(axisId, scaleDiv->lowerBound() * factor , scaleDiv->upperBound() * factor);
    20. doReplot = true;
    21. }
    22. }
    23.  
    24. plt->setAutoReplot(autoReplot);
    25.  
    26. if ( doReplot )
    27. plt->replot();
    28. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 1
    Last Post: 28th January 2010, 13:57
  2. how to add QAction vertically and horizontally in QToolBar
    By sanjayshelke in forum Qt Programming
    Replies: 0
    Last Post: 10th November 2008, 10:56
  3. Replies: 7
    Last Post: 22nd September 2008, 23:05
  4. Rezizing the Qlabels vertically
    By anju123 in forum Qt Programming
    Replies: 3
    Last Post: 3rd January 2008, 16:35
  5. How can I write vertically in a QPushbutton ?
    By castorvert in forum Qt Programming
    Replies: 1
    Last Post: 2nd April 2006, 22:27

Tags for this Thread

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.