QCustomPlot Discussion and Comments

QCustomPlot with multiple QCPAxisRect - "graph area" height with one bottom axisReturn to overview

I have a layout/margin question when having one QCustomPlot with multiple QCPAxisRect:s. I have tried to search for the answer in the support forum but not found the answer.

In my case the QCPAxisRect:s are stacked vertically and to save screen space I use no bottom axis label and the bottom axis tick labels are only enabled / visible for the bottom QCPAxisRect. This works fine but the height of the "graph area" of the last QCPAxisRect then gets a little bit smaller than the other. Whats the best way to automatically make sure that the "graph area" of all the QCPAxisRect:s have the same height?

I assume the issue is that the height of the tick labels (and also axis label if used) is added and thus decrease the available space for the rest.

I'm thinking about how to solve this:
1) Use axisrect->axis(QCPAxis::atBottom)->setTickLabelSide(QCPAxis::LabelSide::lsInside) - i.e. place the tick labels on the inside - this is what I currently do
2) Somehow manually add the tick labels as a separate layout item so that they are not part of the QCPAxisRect
3) Manually set margins or heights
4) ?

Here is an example - https://imgur.com/a/blVtMCK

Best regards
// Stefan

You could use an empty axisRect with no graph just to display the xAxis, and then add for each graph a new axisRect with only yAxis visibleā€¦

hello,BSO
When I use a blank axisRect to display the X-axis, how do I make it take up only the height of the X-axis and not the same height as the other axisRect with graph? (These Axisrects are added to customPlot via the addElement (row, clumn) function, arranged vertically.)

I found a workaround by setting the minimum and maximum dimensions of axisRect, and when the height under the maximum size is set to 1, the axisRect only X-axis looks no different from the other axisRect's own X-axis, which worked perfectly for what I wanted to achieve, thanks to BSO for the ideas! The code looks like the following, if you have a better solution or if there is any problem with my approach, please reply!

QCPAxisRect* channel = new QCPAxisRect(ui->customPlot, false);
channel->addAxes(QCPAxis::atBottom);
ui->customPlot->plotLayout()->addElement(channelNum, 0, channel);// Add to the bottom to act as the X-axis
// Modify the key two lines of code for sizing
channel->setMinimumSize(0,0);
channel->setMaximumSize(QWIDGETSIZE_MAX,1);

Thanks BSO. I used your suggestion and it works great. See https://imgur.com/a/JtSBfFI.