10

I use gnu plot to draw a multiplot and in my script I set the y label like that:

set ylabel "foobar"

Now every plot in the multiplot has a dedicated y label on their y axis. However, I would like to have only one y label for all the plots in the multiplot and center that label also on the common y axis. How can I do that? The multiplot layout I use is a 7.1 So all the plots have the same y axis.

RoflcoptrException
  • 51,941
  • 35
  • 152
  • 200

4 Answers4

6

The simplest way is to make the first plot, then turn off the y label:

set ylabel 'foo'
set multiplot

plot 'data1.dat'

unset ylabel

plot 'data2.dat'
plot ...

unset multiplot

This will make the x-dimension of the first plot different from that of all the other plots, so you may have to play with the margins if you want all the plots the exact same size.

andyras
  • 15,542
  • 6
  • 55
  • 77
  • Thanks a lot, this is a workaround that I'm currently using, but I would like to find a better solution. – RoflcoptrException Jun 29 '13 at 16:03
  • What would you like in the better solution? Plot sizes the same? There is currently no option in gnuplot to have an overall y or x label (or key) for a multiplot. – andyras Jun 29 '13 at 17:36
  • A better solution would be that the label is set automatically to the correct position and not manually with using offset. – RoflcoptrException Jun 29 '13 at 17:45
  • I agree. That is one of the main frustrations I have with multiplot. I just submitted a feature request on the gnuplot sourceforge page. – andyras Jun 29 '13 at 17:59
  • And you will have to move the ylabel with the offset parameter if you want to center it – Vincent Ketelaars May 23 '14 at 13:38
4

Global label workaround

This is not ideal, but if you desperate like me, you can use a rotated global label + larger left margins:

#!/usr/bin/env gnuplot
label_label_size = 14
set terminal png
set output "gnuplot.png"
set multiplot layout 2,1 title "Multiplot with one ylabel" font ",18"
set lmargin 10
set label "My y-label" at screen 0.05,0.5 center front rotate \ 
  font "," . label_label_size
plot sin(x)
set xlabel 'My x-label' font "," . label_label_size
plot cos(x)

enter image description here

Here is a realistic application that motivated me to do this: Heap vs Binary Search Tree (BST)

Tested in gnuplot 5.2 patchlevel 6, Ubuntu 19.04.

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
3

Plot the individual panels of reduced size without labels but with border, tics and title, then define a full-sized panel with labels but without border, tics and title.You may have to plot a dummy function (1/0).

1

This is basically the suggestion from Fabian Claremont's answer, but (for beginners) put into code and visualized. Actually, Ciro Santilli's solution is even shorter.

Tested with gnuplot 5.2. For gnuplot 4.6 (the time of OP's question), replace reset session with reset and set margin 8,-1,1-1 with set lmargin 8 and set bmargin 1.

Code:

### Multiplot with single y-label
reset session
unset key
set sample 500

set multiplot layout 7,1
    unset ylabel
    set linetype 1 lc rgb "red"
    set margins 8,-1,1,-1    # left, right, bottom, top (-1=auto)
    set ytic 1.0
    set title "Plot 1" offset 0,-1
    plot sin(1*x)
    set title "Plot 2" offset 0,-1
    plot sin(2*x)
    set title "Plot 3" offset 0,-1
    plot sin(3*x)
    set title "Plot 4" offset 0,-1
    plot sin(4*x)
    set title "Plot 5" offset 0,-1
    plot sin(5*x)
    set title "Plot 6" offset 0,-1
    plot sin(6*x)
    set title "Plot 7" offset 0,-1
    plot sin(7*x)

    set lmargin -1   # automatic lmargin
    unset title
    set origin 0,0
    set size 1,1
    set border 0
    unset tics
    set ylabel "This is a centered y-label"
    plot [][0:1] -1     # plot a dummy line out of range
unset multiplot
### end of code

Result:

enter image description here

theozh
  • 22,244
  • 5
  • 28
  • 72