PDA

View Full Version : synchronize the X-axis of two plots



eehmke
19th February 2012, 23:46
I have two QwtPlot diagrams that are in a vertical layout. The X axes have the same scale. The Y-axes have different scales and the bottom diagram has a second Y-axis at the right side. This leads to the effect that the X positions are not aligned to each other, making it difficult to interpret the corresponding values. How can I make sure that all corresponding X positions are aligned?

Spitfire
20th February 2012, 09:12
Is your problem the second Y axis that makes the plot smaller thus disaligning the plots?
If yes, then you could use setContentsMargin() on the plot without extra Y axis and set the right margin to the axis widget width.
If no, then I didn't understood your problem.

eehmke
20th February 2012, 12:47
Is your problem the second Y axis that makes the plot smaller thus disaligning the plots?
If yes, then you could use setContentsMargin() on the plot without extra Y axis and set the right margin to the axis widget width.

Thanks, will try that.
It's not only that the first plot does not have a right Y axis. Also the left Y axes have different size because the scale is different (large numbers as major ticks). The contentmargin of the plots seems always to be (0, 0, 0, 0)

Added after 20 minutes:

Ok it works when I put some experimental values into the content margin. Next step would be to calculate them from the font size used to draw the scale ticks. Thanks!

Spitfire
20th February 2012, 15:01
You can tackle different sizes of Y axis widget by setting minimum extent:

QwtScaleDraw* sd = plot->axisScaleDraw( QwtPlot::yLeft );
sd->setMinimumExtent( 50 ); // magic number
plot->setAxisScaleDraw( QwtPlot::yLeft, sd );
this way the widget will be at least that wide. Using that you can ensure that width of the widget is the same across different plots.