'How to plot several Y axis in the left side using gnuplot

I am plotting same plot as from here How to plot multiple y-axes?. But also i would like them to look like in the image below. With additional lines and tics, how can i do it? What I want



Solution 1:[1]

As mentioned in the answer you linked, you can plot many plots on top of each other in the multiplot environment. So, here you are plotting 6 plots on top of each other

  • plot 1, 2, 3 for the data/functions
  • plot 4, 5, 6 for the colored axes
  • and plot 6 as well for the key on top of everything

In order to get the same scale for the plot and the "external" axes I would recommend to store the ranges and step sizes in the variables y10,y11,y1d, ...., such that you have to change the values only at one location.

Script:


reset session

set key opaque box noautotitle

set multiplot
    set margins screen 0.3, screen 0.95, screen 0.95, screen 0.1   # l,r,t,b
    
    # first plot
    set xrange[0:10]
    set xtics 2
    y10 = -1.2
    y11 =  1.2
    y1d =  0.4
    set yrange [y10:y11]
    set ytics y1d
    set format y ''     # no ytic labels
    set grid x,y
    plot sin(x) lc "red"

    # second plot
    set border 0        # no border
    unset tics          # no tics
    unset grid          # no grid
    y20 = -3.0
    y21 =  3.0
    y2d =  1.0
    set yrange [y20:y21]
    plot 3*cos(x) lc "green"

    # third plot
    y30 = -1.5
    y31 =  1.5
    y3d =  0.5
    set yrange [y30:y31]
    plot 3*sin(x)*cos(x) lc "blue"

    # plot for axis 1
    set lmargin screen 0.27
    set border 2 lc "red" lw 2
    set ylabel "Voltage" tc "red" offset 1.5,0
    set yrange [y10:y11]
    set format y
    set ytics y1d nomirror
    plot NaN

    # plot for axis 2
    set lmargin screen 0.17
    set border 2 lc "green" lw 2
    set ylabel "Current" tc "green" offset 0.5,0
    set yrange [y20:y21]
    set ytics y2d
    plot NaN
    
    # plot for axis 3 and key
    set lmargin screen 0.08
    set border 2 lc "blue" lw 2
    set ylabel "Power" tc "blue" offset 1,0
    set yrange [y30:y31]
    set ytics y3d
    plot NaN w l lc "red"   ti "sin(x)", \
         NaN w l lc "green" ti "3*cos(x)", \
         NaN w l lc "blue"  ti "3*sin(x)*cos(x)"
unset multiplot
### end of script

Result:

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1