Is there an easy way to make gnuplot automatically show y1=0 and y2=0 at the same height in the image while the y1 and y2 axes have different scales?

The only way I am aware is to make sure the proportional distance from zero on the high and low bounds are the same for y1 and y2 For example set yrange [-1:2] and set y2range [-10:20] would work because -1 is to -10 as 2 is to 20.

Here's an example

#!/usr/bin/gnuplot -p
set term wxt #not important
unset key
set autoscale
set xrange [0:1]
set xzeroaxis #shows a dotted line where y=0 for y1.
set yrange[-1:2]
#set y2range[-10:20] #if you set an explicit range, it obviously won't work unless you plan it perfectly (like this)
#set y2range[-10:] #this does the minimum to get the plot in the frame (here -10 is the minimum, but the maximum seems to not really matter
#set y2range[:20]
#set y2range[:] #this is equivalent to just not having a set y2range line.
set xtics 0.2
set ytics 0.3
set y2tics 1
set mxtics 5
set mytics 5
set my2tics 5
set ytics nomirror #makes y1tics only show up on the left


plot f(x) axis x1y1 lc rgb 'blue', \
g(x) axis x1y2 lc rgb 'red';

It is not necessarily easier, but a new feature introduced in version 5.0 allows you to link the y2 axis to the y axis. For example, instead of setting a y2 range, you set a forward and reverse mapping from y to y2 and vice versa. Eg

set link y2 via y*10 inverse y/10

Your code (with f(x)=.9) produces an inevitable y2 zero at (y2/10), i.e. y==0.

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.