Search code examples
gnuplot

How to set different heights for separate plots using multiplot


How can one set different heights for two or more plots in multiplot-mode using set size <x>,<y> respecting correct arrangement for the x-axes of the plots? Following problem: I've got a heatmap plot and another linespoint plot with the same time axis. The heatmap plot contains way more information and should use e.g. 80% of the canvas height. Using

set multiplot layout 2,1 margins .1,.8,.05,.95 spacing .05

sets the plots in perfect arrangement but without the possibility to change heights; or at least I didn't manage to get it right. Here are two examples using code from the gnuplot demopage:

$map2 << EOD
0 0 5
0 1 4
0 2 3
0 3 1
0 4 0

1 0 2
1 1 2
1 2 0
1 3 0
1 4 1

2 0 0
2 1 0
2 2 0
2 3 1
2 4 0

3 0 0
3 1 0
3 2 0
3 3 2
3 4 3

4 0 0
4 1 1
4 2 2
4 3 4
4 4 3
EOD 

set multiplot layout 2,1 margins .1,.8,.05,.95 spacing .05
plot '$map2' using 2:1:3 with image
plot sin(x)*cos(x)**2, tan(x)
unset multiplot

which results:

enter image description here

Setting explicit sizes and origins before the plotting commands doesn't have any effect.

Plotting without the margins/spacing option and instead setting explicit sizes and origins for each plot one could only guess the correct x-width for the second plot. Guessing it between .85 and .9 in the code:

$map2 << EOD
0 0 5
0 1 4
0 2 3
0 3 1
0 4 0

1 0 2
1 1 2
1 2 0
1 3 0
1 4 1

2 0 0
2 1 0
2 2 0
2 3 1
2 4 0

3 0 0
3 1 0
3 2 0
3 3 2
3 4 3

4 0 0
4 1 1
4 2 2
4 3 4
4 4 3
EOD 

set multiplot layout 2,1
set size 1,.75
set origin 0.025,.25
plot '$map2' using 2:1:3 with image
set size .85,.25 # <---
set origin 0.025,0
plot sin(x)*cos(x)**2, tan(x)
unset multiplot

lets me plot it like that:

enter image description here

I hope I could explain my question and thanks a lot for your help! It is highly appreciated!


Solution

  • If I have understood your question, you have to only change rmargin and lmargin:

    set size 1,1
    set origin 0,0
    
    unset bmargin, unset lmargin, unset tmargin, unset rmargin
    set multiplot
    
    set size 1,0.8
    set origin 0,0.2
    set lmargin at screen 0.1
    set tmargin at screen 0.95
    set rmargin at screen 0.9
    
    
    plot 'map2.dat' using 2:1:3 with image
    
    set size 1,0.2
    set origin 0,0
    set tmargin 0
    set lmargin at screen 0.1
    set bmargin at screen 0.1
    set rmargin at screen 0.9
    
    plot[GPVAL_X_MIN:GPVAL_X_MAX] sin(x)*cos(x)**2, tan(x)
    
    unset multiplot