Tuesday, March 16, 2010

[SW] Tips for Gnuplot -- Multiplot with EPS output setting

It's very often to show several figures in a single plot. With ``set multiplot,'' gunplot can do this work pretty good. There will be some problems, however, when we don't give proper settings for gunplot. One of the problems I've met was the gnuplot did not print out complete plot containing multiple figures with the terminal set as postscript.

I tried and searched for the solution, and finally got the key. It is better to set the size for the entire plot before the multiplot setting.

Here is my original WRONG setting structure:
  1. set the terminal
  2. set the output filename
  3. set the size for individual figures
  4. set multiplot
  5. set the origin for individual figures
  6. plot individual figures
  7. unset multiplot
And the following is the corrected one:
  1. set the terminal
  2. set the output filename
  3. set the size for the entire plot
  4. set the origin for the entire plot
  5. set multiplot
  6. set the size for individual figures
  7. set the origin for individual figures
  8. plot individual figures
  9. unset multiplot
With the wrong setting structure, we can still get normal output with some terminals such as png. If what we want is something like eps files, then it's necessary to use the right setting structure, which actually makes better sense.

Let me show you the (correct) example.
1 set terminal postscript eps enhanced color solid 20
2 set output "test_nogood.eps"
4 set nokey
5 set size 1,1
6 set origin 0,0
8 set multiplot
10 set tmargin 0.5
11 set bmargin 0.5
12 set rmargin 1.0
13 set lmargin 5.0
15 set xrange [-25:25]
16 set ylabel "f(x)"
17 set noxtics
18 set noytics
20 set size 1,0.20
21 set origin 0.0,0.76
22 set title "sin(x)" offset 0,-1.0
23 plot sin(x) w l lt 1 lw 2
24 set size 1,0.20
25 set origin 0.0,0.54
26 set title "cos(x)" offset 0,-1.0
27 plot cos(x) w l lt 9 lw 2
28 set size 1,0.20
29 set origin 0.0,0.32
30 set title "sin(x)/x" offset 0,-1.0
31 plot sin(x)/x w l lt 3 lw 2
32 set size 1,0.20
33 set origin 0.0,0.10
34 set xlabel "x"
35 set title "x*sin(x)" offset 0,-1.0
36 plot x*sin(x) w l lt 8 lw 2
38 unset multiplot
40 reset

You will get the following plot:
If you change line 5 as ``set size 1,0.20'' and comment out lines 6, 20, 24, 28, and 32, the output result will be as the following plot:
It gives only the last part of the eps file.

Gnuplot FAQ: 7.6 My output files are incomplete!
Visualize your data with gnuplot


  1. Anonymous4:28 AM

    Thank you for posting this. This is just the thing I was trying to figure out how to do.

  2. It's my pleasure. :-)

  3. Anonymous2:22 PM

    Thank You! It's a logical setting, but one has to think of it first... :D

  4. Anonymous9:09 PM

    great thanks, just solved it :) !