How to add white space above multiplot?

Viewed 464

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

2 Answers

My understanding of your question is the following:

  • equal vertical and horizontal subgraph size
  • no space between subgraphs
  • xtics only in the bottom graph (not no xtics as in Ethan's solution)
  • customizable top margin
  • key/legend not in the subgraphs but above top graph (not a label without line as in Ethan's solution)

I guess that's why the multiplot options margins and spacing have been introduced in gnuplot 5.0. Check help multiplot. If you want to have the keys above the top graph, you can set all keys at a fixed screen y-coordinate myKeyY, but you have to distribute the keys and set the x-coordinate yourself or define a function to set the x-positions automatically. Furthermore, you want to set the ytics appropriately to avoid overlap of ytic labels of your zero gap graphs.

Code:

### add space on top of multiplot
reset # session

set multiplot layout 3,1 margins 0.12,0.95,0.11,0.87 spacing 0,0 \
            title "Measurements" font ",14" offset 4,0
    myKeyY = 0.93
    
    unset xlabel
    set format x ""
    set ylabel "[mV]"
    set ytics 5
    set grid xtics, ytics
    set key at screen 0.6,myKeyY
    plot x w l lc "red" title "u"

    set ytics 0,20,80
    set key at screen 0.75,myKeyY
    plot x**2 w l lc "web-green" title "INaK"

    set xlabel "Time [s]"
    set xtics
    set key at screen 0.9,myKeyY
    set ylabel "[nA]"
    set ytics -1000,500,500
    set format "%g"
    plot x**3 w l lc "web-blue" title "Ito"

unset multiplot
### end of code

Result:

enter image description here

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

Related