Search code examples
matplotlibdata-visualizationgnuplotdata-analysissubplot

How to add white space above multiplot?


I'm using the multiplot environment of gnuplot. I'm having trouble to find a way to increase the white space above all the plots to make some room for the legends. I managed to add a white space below the plots by declaring a layout of 4,1 but using actually only the first three subplot. (so the bottom one is blank and I can put the xlabel). If I increase the margin on top then the first plot get squeezed, like in the figure. How Can I add this extra white space above keeping the same height of all the subplots in a simple way. Here I put my simple code

 


set term pdfcairo size 6,4
set output "currents.pdf"
set xrange [0:1]

set tmargin 0
set bmargin 0
set lmargin 10
set rmargin 2


set multiplot layout 4,1 


############################################# PLOT 1
set tmargin 2

set grid xtics ytics lt 1 lc "grey"

set ytics (-50,-40,-30,-20,-10,0,10,20,30)

set format x ''

set ylabel "[mV]" offset -3,0

set key at screen 0.8,0.97

plot "ionic_model_0d.csv" using 1:2 title "u" with lines lt 2 lc "red"

set tmargin 0 



################################################# PLOT 2
set key at screen 0.4,0.97

plot "ionic_currents.csv" using "Time":"INaK" with lines 



################################################# PLOT 3
set format x "%1.1f" 

set yrange [-0.002:0.022]

set xtics  (0,0.2,0.4,0.6,0.8,1)

set ytics (0.002,0.006,0.01,0.014,0.018,)

set ylabel "[nA]" offset 0,0

set xlabel "Time [s]"

set grid xtics ytics lt 1 lc "grey"  

set key at screen  0.68,0.97

plot "ionic_currents.csv" using "Time":"Ito" with lines lt 2 lc "blue" 


unset multiplot 

myplots


Solution

  • set lmargin screen 0.1
    set multiplot layout 4,1 
    set multiplot next         # skip the first plot
    plot x
    plot x**2
    set label 1 center at screen 0.5, 0.95
    set label 1 "Some title that goes above all the plots"
    plot x**3
    unset multiplot
    

    enter image description here

    Edit: Here is an alternative approach. Because the title font is specified to be large (50pt in this example), extra room is reserved for it. But you can be clever with the actual text and switch back to a smaller font. Or you can use whitespace " " for the title so that the space is reserved and then use that space with a separate set label command.

    set margins 10,10,0,0
    unset xtics
    
    set multiplot layout 4,1 title "Overall title" font ",50" offset 0,-1 right
      plot x
      plot x**2
      set label 1 at screen 0.6, 0.95 left "Label line 1\nline 2\nline 3"
      plot x**3
    unset multiplot
    

    enter image description here