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 multiple plots by gnuplot. I don’t want that 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

11 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

  6. I want to add xtics at different plot in the stack.
    What have to do?
    Thanks
    K.S.

    Comment by Kanchan Sarkar — July 17, 2010 @ 4:41 pm | Reply

  7. Again How can one add title to different plots in the stack?

    Comment by Kanchan Sarkar — July 17, 2010 @ 4:52 pm | Reply

  8. I got answers.

    Comment by Kanchan Sarkar — July 17, 2010 @ 5:54 pm | Reply

  9. Hi,
    Thank you for the example. I have a question about it. The output that I get doesn’t look like the one you provided. Do you know what the problem might be?
    Thanks!

    Comment by randaasad — July 20, 2011 @ 12:22 am | Reply

    • perhaps it’s about the version of GnuPlot. The script shown at here was created 4 years ago. I may use GnuPlot 3.5 at that time. I was having lots of problem using my old scripts for GnuPlot 4.0 and above.

      Comment by kpwu — July 20, 2011 @ 1:00 am | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Theme: Rubric. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.