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
Re: Show a scale for the same axis on both sides of the plotcanvas
Quote:
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 );
Quote:
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
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:
Code:
connect(axisWidget(yLeft), SIGNAL(scaleDivChanged()), this, SLOT(updateRightScale()));
updateRightScale();
connect(axisWidget(xBottom), SIGNAL(scaleDivChanged()), this, SLOT(updateTopScale()));
updateTopScale();
Code:
void Plot::updateRightScale() {
axisWidget(yRight)->setScaleDiv(axisScaleEngine(yLeft)->transformation(), *axisScaleDiv(yLeft));
}
void Plot::updateTopScale() {
axisWidget(xTop)->setScaleDiv(axisScaleEngine(xBottom)->transformation(), *axisScaleDiv(xBottom));
}
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:
Code:
Plot plot;
plot.setTitle(m_iqeCurveName);
axisFont.setPointSize(14);
axisFont.setBold(true);
plot.
setAxisFont(QwtPlot::xBottom, axisFont
);
plot.
setAxisFont(QwtPlot::yLeft, axisFont
);
PlotCurve rMeasCurve;
rMeasCurve.update(m_R_meas);
rMeasCurve.setEnabled(true);
rMeasCurve.setPlot(&plot);
rMeasCurve.setName("R_meas");
rMeasCurve.setColor(Qt::green);
rMeasCurve.setLineWidth(2);
plot.setDefaultRange(250, 1200, 0, 1.1);
plot.replot();
plot.saveImage(outputDir.absoluteFilePath("R/R "+ ID + ".png"));
with the following for setDefaultRange:
Code:
void Plot::setDefaultRange(double minX, double maxX, double minY, double maxY) {
setAxisScale
(QwtPlot::xBottom, minX, maxX
);
setAxisScale
(QwtPlot::xTop, minX, maxX
);
setAxisScale
(QwtPlot::yLeft, minY, maxY
);
setAxisScale
(QwtPlot::yRight, minY, maxY
);
replot();
m_zoomer->setZoomBase(false); // setzt den aktuellen Zoom als Standard?
}
Any ideas?
Re: Show a scale for the same axis on both sides of the plotcanvas
Problem #1 can be solved like this:
Code:
connect(m_zoomer,
SIGNAL(zoomed
(QRectF)),
this,
SLOT(updateSecondaryAxis
(QRectF)));
void Plot
::updateSecondaryAxis(const QRectF &zoomRect
) { setAxisScale
(QwtPlot::xTop, zoomRect.
left(), zoomRect.
right());
setAxisScale
(QwtPlot::yRight, zoomRect.
top(), zoomRect.
bottom());
replot();
}
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.
Re: Show a scale for the same axis on both sides of the plotcanvas
Quote:
Originally Posted by
SimonSchmeisser
Code:
void Plot::updateRightScale() {
axisWidget(yRight)->setScaleDiv(axisScaleEngine(yLeft)->transformation(), *axisScaleDiv(yLeft));
}
It has to look like this:
Code:
void Plot::updateRightScale() {
setAxisScaleDiv( yLeft, *axisScaleDiv(yLeft));
}
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
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