aligning plots and color bar
Hi,
I need to align 2 plots : one containing a QwtPlotCurve and the other one a QwtPlotSpectrogram. Both are arranged in a vertical layout (QVBoxLayout - it's a waterfall plot).
I used some parts of the example (playground) "plotmatrix" to ensure that both plots stay aligned. BUT, there's one problem : when enabling the QwtPlotSpectrogram's right axis color bar, the plots are no more aligned.
can "plotmatrix" be easily updated to take in account the width of the color bar ?
Another solution is to create a 2x2 QGridLayout, put the curve in (0,0), the spectrogram in (1,0) and a QwtScaleWidget (with a color bar enabled) in (1,1). Otherwise, if having the yRight + color bar axis enabled on the QwtPlotCurve plot is not annoying, that also will fix the alignment issue.
Thanks.
Re: aligning plots and color bar
The plotMatrix example is aligning the vertical scales by using QwtScaleDraw::setMiniumExtent.
So your code is probably somehow like this ( untested ):
Code:
auto s1
= spectrogramPlot
->axisWidget
( QwtPlot::yRight );
auto s2
= curvePlot
->axisWidget
( QwtPlot::yRight );
s2->scaleDraw()->setMinimumExtent( 0.0 );
qreal extent = s1->scaleDraw()->extent( s1->font() );
extent -= s2->extent( s2->font() );
extent += s1->colorBarWidth() + s1->spacing();
s2->scaleDraw()->setMinimumExtent( extent );
Uwe
1 Attachment(s)
Re: aligning plots and color bar
Hi Uwe,
It didn't work :( I also used your code snippet in in the plot matrix example and it didn't work too.
Attachment 13322
I think I'll do plan B : using a separate QwtScale widget to handle spectrogram's color bar. I really don't like this solution, it's cumbersome.
I'll be very happy if you can help me to fix my problem : https://github.com/embeddedmz/QwtWaterfallplot I'm struggling with it since this last summer.
Thanks.
Re: aligning plots and color bar
Quote:
Originally Posted by
embeddedmz
It didn't work :( I also used your code snippet in in the plot matrix example and it didn't work too.
It didn't work is not a very helpful information. Don't you you have an effect when increasing the minimum extent for the right axis of the upper plot ?
Uwe
2 Attachment(s)
Re: aligning plots and color bar
You're right Uwe !
Now it looks better but there's still some adjustments that have to be made and I hope that you can help me :
Attachment 13325
First of all, there's these 2 lines in the constructor that triggers everything, the issue is that if I don't rescale X axis of one of the two plots, the alignement logic will not be executed and I don't know how to handle this (plotmatrix playground). For example, to obtain the result shown in the screenshot above, I used the zoomer to zoom a region of the waterfall.
Code:
connect(m_plotCurve
->axisWidget
(QwtPlot::xBottom),
&QwtScaleWidget
::scaleDivChanged,
this, &Waterfallplot::scaleDivChanged/*, Qt::QueuedConnection*/);
connect(m_plotSpectrogram
->axisWidget
(QwtPlot::xBottom),
&QwtScaleWidget
::scaleDivChanged,
this, &Waterfallplot::scaleDivChanged/*,Qt::QueuedConnection*/);
void Waterfallplot::scaleDivChanged()
{
// apparently, m_inScaleSync is a hack that can be replaced by
// blocking signals on a widget but that could be cumbersome
// or not possible as the Qwt API doesn't provide any mean to do that
if (m_inScaleSync)
{
return;
}
m_inScaleSync = true;
if (m_plotCurve
->axisWidget
(QwtPlot::xBottom) == sender
()) {
updatedPlot = m_plotCurve;
}
else if (m_plotSpectrogram
->axisWidget
(QwtPlot::xBottom) == sender
()) {
updatedPlot = m_plotSpectrogram;
}
else
{
updatedPlot = nullptr;
}
if (updatedPlot)
{
QwtPlot* plotToUpdate
= (updatedPlot
== m_plotCurve
) ? m_plotSpectrogram
: m_plotCurve;
plotToUpdate
->setAxisScaleDiv
(QwtPlot::xBottom,
updatedPlot
->axisScaleDiv
(QwtPlot::xBottom));
updateLayout();
}
m_inScaleSync = false;
}
void Waterfallplot::alignAxis(int axisId)
{
// 1. Align Vertical Axis (only left or right)
double maxExtent = 0;
{
sd->setMinimumExtent(0.0);
const double extent = sd->extent(scaleWidget->font());
if (extent > maxExtent)
{
maxExtent = extent;
}
}
{
sd->setMinimumExtent( 0.0 );
const double extent = sd->extent(scaleWidget->font());
if (extent > maxExtent)
{
maxExtent = extent;
}
}
{
scaleWidget->scaleDraw()->setMinimumExtent(maxExtent);
}
{
scaleWidget->scaleDraw()->setMinimumExtent(maxExtent);
}
}
void Waterfallplot::alignAxisForColorBar()
{
auto s1
= m_plotSpectrogram
->axisWidget
(QwtPlot::yRight);
auto s2
= m_plotCurve
->axisWidget
(QwtPlot::yRight);
s2->scaleDraw()->setMinimumExtent( 0.0 );
qreal extent = s1->scaleDraw()->extent(s1->font());
extent -= s2->scaleDraw()->extent(s2->font());
extent += s1->colorBarWidth() + s1->spacing();
s2->scaleDraw()->setMinimumExtent(extent);
}
void Waterfallplot::updateLayout()
{
// 1. Align Vertical Axis (only left or right)
alignAxisForColorBar();
// 2. Replot
m_plotCurve->replot();
m_plotSpectrogram->replot();
}
Please can you take a look at what I did : https://github.com/embeddedmz/QwtWaterfallplot and help me to enhance it.
I think it's a good idea to create a new Qwt example, for the data one can use the spectrogram example data and display it slowly ! Otherwise, I'm going to add a curve plot at the left of the spectrogram, and that will allow a user to select a point on the spectrogram and use the curve plot above the waterfall to plot the layer in function of the spectrogram X axis and the the curve plot at the left of the spectrogram will be used to plot the vertical waterfall slice in function of time (the curves reflects the cross described by the point). I think this is a better example.
Thanks.
1 Attachment(s)
Re: aligning plots and color bar
I managed to fix all the issues even though that led me to write ugly code, but the final result is awesome :
Attachment 13326
Re: aligning plots and color bar
Quote:
Originally Posted by
embeddedmz
I managed to fix all the issues even though that led me to write ugly code, but the final result is awesome :
Attachment 13326
I have the same problem!
Re: aligning plots and color bar
Re: aligning plots and color bar
Oh crap, when setting spectrogram and X/Y/Z titles, that broke the alignments of both curves with the spectrogram.
Dear Uwe, how can I determine the amount of space (pixels ?) that the titles are occupying ? Can you please help me to fix this issue just like you did with the color bar ? Thank you.
By the way, I played with the "plotmatrix" example, and it doesn't take in account the plot's titles !
Re: aligning plots and color bar
Encountered the same problem. When one plot uses colorbar and another one does not, 'plotmatrix' example does not work. Colorbar is not covered by scale extents.
My solution was to create fictitious invisible axis with colorbar.