My software notes

November 20, 2007

[gnuplot] make a multiplot (3 stacked plots)

Filed under: softwares and scripts — kpwu @ 9:57 pm

Here is an example I made to generate a multiplot by gnuplot. I don’t want the 3 plots have space in between the x-axis. So the trick thing is: set the margin (r, l, t,b) very smaller,e.g. 0.01. Then the output looks “like” 3 stacked plots. You can modify it by 3 connected plots in a row (left, middle, right).

The plot is shown here:
data.png

The scripts is pasting here:
=========================
set terminal postscript
set output “data.ps”
unset key
NX=1; NY=3
DX=0.01; DY=0.01; SX=0.85; SY=0.25
set bmargin DX; set tmargin DX; set lmargin DY; set rmargin DY
## set the margin of each side of a plot as small as possible
## to connect each plot without space
set size SX*NX+DX*1.5,SY*NY+DY*1.8
set multiplot
##—— First Figure–bottom
set size SX,SY
set xrange [0:140]
set yrange [-0.9:0.9]
set ytic -0.6,0.3,0.6 ### from -0.6 to 0.6 with 0.3 interval
set origin DX,DY;
plot sin(x)
###——Second Figure—middle
set origin DX,DY+SY;
unset xtics
plot sin(x**2)
##——- Third Figure—-top
set origin DX,DY+SY*2
plot cos(x)
unset multiplot

6 Comments »

  1. This is a nice script. If I want to include the x label and ylabel what else should I include?

    Comment by prakash — March 3, 2009 @ 4:10 am | Reply

  2. just add the lines in proper places.
    e.g.
    set xlabel time
    set ylabel intensity

    Comment by kpwu — March 3, 2009 @ 8:12 am | Reply

  3. Good ! What if I wish to also place a ylabel. The stack of three plots becomes a complete mess. I have tried offset etc. and the mess gets worse. Any solution ?

    - Atish .

    Comment by Atish — March 26, 2009 @ 12:45 pm | Reply

  4. Sorted out with ’set lmargin’. Thanks !

    Comment by Atish — March 26, 2009 @ 12:51 pm | Reply

  5. Meanwhile, gnuplot supports automatic layout for stacked plots.

    See the demo (scroll to bottom):

    http://gnuplot.sourceforge.net/demo_4.3/layout.html

    Comment by Walter — July 27, 2009 @ 9:28 am | Reply


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.