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:
Code:
mag
->setAxisEnabled
(QwtPlot::yLeft,
true);
mag
->setAxisEnabled
(QwtPlot::xBottom,
false);
mag->setMouseButton(Qt::NoButton);
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 :)
Re: Magnify plot vertically while keeping position of baseline constant
Overload QwtPlotMagnifier::rescale(). Looking into into its implementation will help with your code.
Uwe
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:
Code:
void Magnifier::rescale(double factor)
{
factor = qwtAbs(factor);
if ( factor == 1.0 || factor == 0.0 )
return;
bool doReplot = false;
const bool autoReplot = plt->autoReplot();
plt->setAutoReplot(false);
for ( int axisId
= 0; axisId <
QwtPlot::axisCnt; axisId
++ ) {
const QwtScaleDiv *scaleDiv
= plt
->axisScaleDiv
(axisId
);
if ( isAxisEnabled(axisId) && scaleDiv->isValid() )
{
plt->setAxisScale(axisId, scaleDiv->lowerBound() * factor , scaleDiv->upperBound() * factor);
doReplot = true;
}
}
plt->setAutoReplot(autoReplot);
if ( doReplot )
plt->replot();
}