[ACCEPTED]-Removing blank gap in gnuplot multiplot-gnuplot

Accepted answer
Score: 26

Getting the margins right with multiplot is a bit 15 tedious, especially when using set pm3d map, which has 14 quite large margins.

Since version 5.0

Since 5.0 version,multiplot has 13 the options margins and spacing.

margins takes four numbers set multiplot margins <left>,<right>,<bottom>,<top>, which 12 give the fixed overall margins around the 11 multiplot layout. spacing takes two number set multiplot spacing <xspacing>,<yspacing> which 10 give the distance between two rows (<yspacing>) or 9 two columns (<xspacing>).

set terminal pngcairo size 800,600 background rgb '#bbbbbb'
set output 'foobar.png'

set multiplot layout 2,2 \
              margins 0.1,0.98,0.1,0.98 \
              spacing 0.08,0.08

set ylabel 'ylabel'
plot x

unset ylabel
plot 2*x

set ylabel 'ylabel'
set xlabel 'xlabel'
plot 3*x

unset ylabel
plot 4*x
unset multiplot

Result (with 5.0rc1):

enter image description here

Earlier versions, kept only for completeness

To achieve 8 the same thing with gnuplot 4.x, you must 7 do the calculations by hand or define some 6 functions, like the following example shows. This 5 should be quite universally usable.

You can 4 put all the general stuff in a configuration 3 file, like multiplot.gp, which contains the functions

init_margins(left, right, bottom, top, dx, dy, rows, cols) = \
  sprintf('left_margin = %f; right_margin = %f; top_margin = %f; bottom_margin = %f; ', left, right, top, bottom) . \
  sprintf('col_count = %d; row_count = %d; gap_size_x = %f; gap_size_y = %f', cols, rows, dx, dy)

get_lmargin(col) = (left_margin + (col - 1) * (gap_size_x + ((right_margin - left_margin)-(col_count - 1) * gap_size_x)/col_count))
get_rmargin(col) = (left_margin + (col - 1) * gap_size_x + col * ((right_margin - left_margin)-(col_count - 1) * gap_size_x)/col_count)
get_tmargin(row) = (top_margin  - (row - 1) * gap_size_y - (row-1) * ((top_margin - bottom_margin  - gap_size_y * row_count) / row_count))
get_bmargin(row) = (top_margin  - (row - 1) * gap_size_y -  row    * ((top_margin - bottom_margin  - gap_size_y * row_count) / row_count))
set_margins(col, row) = \
  sprintf('set lmargin at screen %f;', get_lmargin(col)) . \
  sprintf('set rmargin at screen %f;', get_rmargin(col)) . \
  sprintf('set tmargin at screen %f;', get_tmargin(row)) . \
  sprintf('set bmargin at screen %f;', get_bmargin(row))         

The 2 main file is then

set terminal pngcairo size 800,600 background rgb '#bbbbbb'
set output 'foobar2.png'

load 'multiplot.gp'

eval(init_margins(0.1, 0.98, 0.1, 0.98, 0.08, 0.08, 2, 2))    
set multiplot

eval(set_margins(1,1))
set ylabel 'ylabel'
plot x

eval(set_margins(2,1))
unset ylabel
plot 2*x

eval(set_margins(1,2))
set ylabel 'ylabel'
set xlabel 'xlabel'
plot 3*x

eval(set_margins(2,2))
unset ylabel
plot 4*x
unset multiplot

With the result (using 1 4.6.4):

enter image description here

Score: 2

In multiplot by using set lmargin, set rmargin, set bmargin and set tmargin, for left, right, bottom, top 9 margin around your graph, you have the best 8 control of the positioning of your graphs. In 7 my experience it gives you a bit more freedom 6 than the layout option you are using now.

A good 5 example of how to does this for a single 4 graph is found here: http://www.gnuplotting.org/multiplot-placing-graphs-next-to-each-other/

Another approach is 3 to define functions to set the margin, which 2 is easier if all your graphs are the same 1 size, see: http://www.sciencetronics.com/greenphotons/?p=570

Score: 0

If all have the same xlabel and ylabel you 1 can use this

set terminal postscript eps enhanced color
set output 'YOUR_GRAPH.eps'

L = 0.14
R = 0.95

TOP=0.98
DY = 0.29

set multiplot

set offset 0,0,graph 0.05, graph 0.05

set ylabel 'XLABEL' offset 1
set xlabel 'YLABEL'


set tmargin at screen TOP-1.65*DY
set bmargin at screen TOP-3*DY
set lmargin at screen R-6*L
set rmargin at screen R-3*L
plot "YOUR_DATA.dat" title"TITLE 1" 

set ytics format ''
unset ylabel
set lmargin at screen R-3*L
set rmargin at screen R
plot "YOUR_DATA2.dat" title"TITLE 2"


####################################################################

set format y "%.2f"
set ylabel 'd' offset 1
set tmargin at screen TOP
set bmargin at screen TOP-1.35*DY

set lmargin at screen R-6*L
set rmargin at screen R-3*L
plot "YOUR_DATA3.dat" title"TITLE 3"

set ytics format ''
unset ylabel
set lmargin at screen R-3*L
set rmargin at screen R
plot "YOUR_DATA4.dat" title"TITLE 4"

More Related questions