6
votes

I'm trying to put two figures side by side using gnuplot with multiplot. I want the resulting image to be rectangular so I use set size 2, 1. I also set the set multiplot layout 1, 2 option. However, the resulting image only uses the left part of the available space. Any help will be appreciated. Thanks Ahmet

Here is the resulting image http://tinypic.com/r/33mlz04/6

And below is the gnuplot commands I'm using.

set terminal postscript eps color enhanced
set output 'figure.eps'; 
set size 2,1;

set multiplot layout 1, 2 ;
set title "Figure 1";
  plot  "data1.txt" 
set title "Figure 1";
 plot  "data2.txt" 
unset multiplot

Although I'm not very sure, with some trial and error I have solved it


    set terminal postscript eps color enhanced 

    set output 'eps/image.eps'; 
    set size 1,0.5;

    set multiplot layout 1, 2 ;
    set title "Figure 1";
    set size 0.5,0.5;
    plot  "data/data1.txt" 
    set title "Figure 1";
    set size 0.5,0.5;
    plot  "data/data2.txt" 
    unset multiplot

3
Welcome to StackOverflow! As a matter of style, you don't need trailing semicolons in gnuplot (as you would in C) ... while they don't hurt, they tend to make the script a little less readible (IMHO). Also, if you found the solution by @andyras useful, feel free to upvote or even mark it as the accepted solution.mgilson

3 Answers

9
votes

Try something like:

set terminal postscript eps color enhanced size 10,5
set output 'figure.eps';

set multiplot layout 1, 2 ;
set title "Figure 1";
plot  "data1.txt" 
set title "Figure 1";
plot  "data2.txt" 
unset multiplot

When you set the size on the terminal specification line, that determines the actual size of the plot canvas (in inches in this case). When you use set size on a separate line, that sets the size of the plot in relative units of the canvas size. This is different in older versions of gnuplot. For perhaps a better explanation, try help set size in gnuplot.

4
votes

For even more control over the size/position of the plot, you can use set origin in conjuction with set size to change the placement and size of each plot. Finally, the most control can be achieved with set lmargin at <place> (and set rmargin ...) and so-on for tmargin and bmargin where the "lrtb" stand for left, right, top and bottom respectively.

So, to get a plot to fill all of the available space (left to right), you could:

set multiplot
set lmargin at 0
set rmargin at .5
plot sin(x)
set lmargin at .5
set rmargin at 1
plot cos(x)
unset multiplot

However, this is (usually) overkill. Usually gnuplot tries to make the margins big enough for your labels and such, but setting the margin explicitly disables that. I would suggest you go with the solution by andyras.

1
votes

if you are having problems using this method for more than 2 figures add 'set origin 0,0' after 'set size 0.5,0.5'. For example, for three figures :

set terminal postscript eps color enhanced 

set output 'eps/image.eps'; 
set size 1.5,0.5;

set multiplot layout 1, 3 ;
set title "Figure 1";
set size 0.5,0.5;
set origin 0,0
plot  "data/data1.txt" 
set title "Figure 2";
set size 0.5,0.5;
set origin 0,0
plot  "data/data3.txt"
set title "Figure 3";
set size 0.5,0.5;
set origin 0,0
plot  "data/data3.txt" 
unset multiplot