QCustomPlot Discussion and Comments

How to link a single plot to two xAxis?Return to overview

I want to plot my data on xAxis and xAxis2 simultaneously, but can not figure out an elegant way to do this, that does not screw up e.g. automatic rescaling. To make this more precise: i have a spectrum, whose counts i want to plot on the yAxis, but on the bottom xAxis i want to have the energy and on the top xAxis2 the corresponding channels. Both xAxis have the same tick interval, so in theory i am just looking for a way to swap out the labels of my top xAxis2 and it would be fine.
Is there any way to do this or is this just not an intended usecase right now?

Thanks in advance for any kind of help on this subject.
Greetings,
Jannick

Actually all you need is a slot connected to your rangeChanged signal of the bottom xAxis, and in that slot set the accordingly transformed range for the xAxis2. In that scenario, the xAxis2 isn't directly connected to any graphs.

Worked like a charm! Thank you very much!