QCustomPlot Discussion and Comments

Example of independent right and left y-axis scaling?Return to overview

Does someone have a code example of generating a plot with independent scaling of two graphs using a common X axis and independent left and right Y axes?

I have a dataset of current and voltage vs. time and want the current scale on the left and the voltage scale on the right. I can set the static axes scales just fine, but then when I try mouse-based zoom or drag, the scale of both the right and left axes track. I want them independent.

Thanks!

I figured out that I needed to use setRangeDragAxes() and setRangeZoomAxes() with a QList of the axes I want to drag or zoom.

Since I didn't readily find an example of doing this on the QCustomPlot website, I created a slightly modified interaction-example and put it up on GitHub:

https://github.com/mmccullo/qcustomplot-interaction-example

It allows all four axes (left, right, top, and bottom) to be selected and dragged or scaled individually.

I'd also like to get the legend or graph selection working so that the appropriate axes pair is dragged or scaled when an individual graph is selected. Any hints appreciated!

GitHub example repo noted above has been updated with code to drag and zoom based on the current graph selection if no axis is presently selected.

This supports unlimited Y axes with independent scaling. X-Axes are locked.
https://github.com/BGraco/SmartPlot

QCustomPlot allows additional Y-axes as well, but I was specifically looking for example code that allows independent scaling of the left and right axes (which I did not readily find in the existing examples). The modified example that I posted on GitHub shows how to do that for others that might have the same need.