Search code examples
gnuplotaxes

Gnuplot: how draw an arrow using axis of x1y2


We can draw an arrow using:

set arrow 1 from 0,-5 to 0,5

However, the from and to positions are using the x1y1 axis.

How can I let the positions use the x1y2 axis? I have a y2 axis different from y1 axis.


Solution

  • Use the second coordinate system:

    # Set different ranges for y1 and y2
    set y2range [-1:1]; set yrange [-10:10]; set xrange [-2*pi:2*pi]; set y2tics
    set multiplot layout 2,1
    # Set arrow using x1y1 coordinate system
    set arrow 1 from 0,0 to 1,1
    plot sin(x)
    # Set arrow using x2y2 coordinate system (x2 = x1 because x2 is not set)
    set arrow 1 from second 0,0 to second 1,1
    plot sin(x)
    

    You can see the difference:

    enter image description here