3 October 2006
Linked Axes In gnuplot

It is sometimes nice to display two x or y axes, when there is a well defined transformation between the two. For example, it is common to see value plotted against of wavelength (nm) and photon energy (eV) or alternatively wavelength (nm) and photon frequency (Hz). These plots have so called ‘linked axes’.
Unfortunately, this isn’t a feature of gnuplot. It would be nice to simply enter the transform equation which converts from the ‘x1′ axis to the ‘x2′ axes and places x2 tics at ‘nice’ round number positions for that unit. However, this behaviour can be approximated by using the set x2tics command, to produces something like this:

This can be achieved by manually calculating the values on the x2 axis you want tics marks to appear then entering their ‘x1 co-ordinate’ using the set x2tics command. For example, the process uses above was:
Step #1
Find the range of x2 values that will fit ‘nicely’ in the x1 range. x1 goes from 400-800 so my x2 values turned out to be ~3.0 to ~1.73. I then decided to increment x2 in steps of 0.25 which meant I have six x2 values which fits nicely into the x1 range.
Step #2
Calculate what above x2 values (i.e. 3.0, 2.75, 2.5, 2.25, 2.0, 1.75) are in you x1 unit (i.e. 400, 451, 494, 551, 620, 708).
Step #3
Use x2tics to place the x2 tics at the above x1 positions:
set x2tics ("3.0" 400, "2.75" 451.00, "2.5" 494, "2.25" 551, "2.0" 619.98, "1.75" 707.98 )
For the sake of completeness you can convert from nm to eV via:
nanometersValue = 1e9*((h*c)/(q*electronVoltValue));
And you probably won’t be reading this if you don’t know what the symbol for Planck’s constant, the speed of light or the charge on the electron are so I won’t bother telling you what h,c and q mean – oops.

