Align ylabel in gnuplot multiplot

Viewed 108

Is there a way to align vertically the y labels of in gnuplot's multiplot so that they are below each other? The problematic example is below (the red line is annotation showing the problem):

set xrange[0:10]
set multiplot layout 2,1 margins 0.1,0.95,0.1,0.95 spacing 0,0
set ylabel "y1\nlabel"
set ytics
set format y "%.2f"
plot -1000*cos(x)**2 w l lt 4 lw 2
set ylabel "y2\nlabel"
set format y "%.1f"
plot cos(x) w l lt 5 lw 2
unset multiplot

which generates: enter image description here

And I would like to automatically position the labels such, that the red annotated line "touches the same text". Note that I am really interested in automatic way or more correct way that a workaround using a trial and error with set ylabel "lable" offset -x,0

1 Answers

As you already noted, you can set an offset to the x- or y-label (check help xlabel), however, no absolute position. This you can do with setting your own label. You can set the position relative to the screen and/or relative to the graph. gnuplot keeps these values for the second plot, no need to specify again. Check help label.

Check the following example:

Code:

### align ylabels in multiplot
reset session

set xrange[0:10]

set multiplot layout 2,1 margins 0.15,0.95,0.1,0.95 spacing 0,0
    
    set format x ""
    unset ylabel
    set label 1 "y1\nlabel" at screen 0.02, graph 0.5 center rotate by 90
    set ytics 200
    set ytics add ("" -1000)   # remove -1000
    set format y "%.2f"
    set grid x,y
    plot -1000*cos(x)**2 w l lt 4 lw 2
    
    set format x
    set label 1 "y2\nlabel"
    set ytics 0.4
    set format y "%.1f"
    plot cos(x) w l lt 5 lw 2

unset multiplot
### end of code

Result:

enter image description here

Related