Search code examples
gnuplot

Adding more than one yrange on the left hand side of the plot using gnuplot


Is it possible to add more then one yrange on the left hand side of the plot using gnuplot? See the figure linked below, please.

enter image description here

Ideally I would need yrange commands such as y3range, y4range, etc.

Using multiplot I could not get what I want.

set multiplot
set lmargin at scr 0.2
set bmargin at scr 0.1 # fix bottom margin
set grid
set y2range [0:20]
plot x, 2*x axes x1y2  # this is your actual plot

unset grid
set lmargin at scr 0.2
set bmargin at scr 0.15 # fix bottom margin
set yrange [0:20]    # set yrange to the same as y2 in the first plot
set border 0         # switch off all borders except the left   
unset xtics          # switch off the stray xtics
plot -1000 notitle   # plot something outside of the y(2)range
unset multi

enter image description here Thank you for your help.


Solution

  • You have to set the yranges accordingly such that the ytics and hence the grid are nicely aligned. Add an offset to the ytics to tune the distances. Check help xtics.

    Code:

    ### multiple axes
    reset session
    
    # common settings for all (sub-)plots
    set lmargin at screen 0.15
    set bmargin at screen 0.12
    
    set xlabel "my x-title"
    set xrange[0:3000]
    set grid
    set ytics font ",8"
    
    myOffsetY = 0.7
    
    set multiplot
        set ylabel "my 1st y-label" tc rgb "red" offset -2,0
        set yrange [-10:6]
        set ytics -10,2 tc rgb "red" offset 0,0
        plot 0.001*x-10 w l lc rgb "red" notitle
    
        set xlabel " "
        unset xtics
        unset grid
        set ylabel "my 2nd y-label" tc rgb "green" offset 2,0
        set yrange [-10.0:-2.0]
        set ytics -10, 1 tc rgb "green" offset 0,-myOffsetY
        set format y "%.1f"
        plot 0.002*x -10w l lc rgb "green" notitle
    
        set ylabel "my 3rd y-label" tc rgb "blue" offset -4,0
        set yrange [-60:20]
        set ytics -60, 10 tc rgb "blue" offset 0,myOffsetY
        set format y "%.0f"
        plot 0.003*x-10 w l lc rgb "blue" notitle
    
    unset multiplot
    ### end of code
    

    Result: enter image description here