如何使用 gnuplot 在左侧绘制多个 Y 轴

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

我正在绘制与此处相同的图 How to plot multiple y-axes?。但我也希望它们看起来像下图所示。有了额外的线条和抽动,我该怎么做?

正如您链接的答案中提到的,您可以在 multiplot 环境中绘制许多相互重叠的图。 所以,在这里你在彼此之上绘制 6 个地块

  • 情节 1、2、3 为 data/functions
  • 为彩色坐标轴绘制 4、5、6 图
  • 并绘制 6 以及所有内容之上的键

为了使绘图和“外部”轴具有相同的比例,我建议将范围和步长存储在变量 y10,y11,y1d, .... 中,这样您只需在一个位置。

脚本:


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

结果: