Monday, November 7, 2011

Multiple output files with Gnuplot

Making figures with Gnuplot one may want to generate more than one figure using a one script. For example if you are analyzing data you may want to present parts of your data in different figures. One can prepare more than one figure using Gnuplot in two ways. The first one is to prepare a multiplot figure where one physical file contains more than one figure. Second option is to prepare multiple files with separate figures using a one Gnuplot script. The script below shows how to organize the Gnuplot script to prepare three different files with sine cosine and tangent functions plotted in separate files.
#!/usr/bin/gnuplot 
set terminal postscript eps enhanced color "Helvetica" 24

# change the line styles 
set style line 1 lt 1 lw 2 pt 5 ps 1 lc rgb "#d61818"
set style line 2 lt 2 lw 2 pt 9 ps 1 lc rgb "#072c76"

# set labels and ranges for axes
set xlabel "x"
set ylabel "y"
set xrange [-pi:pi]
set yrange [-1:1]

# plot 1
set output "plot1.eps"
plot sin(x) ls 1

# plot 2
set output "plot2.eps"
plot cos(x) ls 1

# plot 3
set output "plot3.eps"
plot tan(x) ls 1, sin(x)/cos(x)+pi ls 2
The crux is to set a different output file before the plot command. The script above has three plot calls for sine, cosine and tangent functions separately and all of them are preceded by the output file statements. The script prepares three different postscript files named plot1.eps, plot2.eps and plot3.eps having the plots mentioned before. All definitions common for the three plots, like the axes labels and ranges or the line styles definitions are given at the top of the script and are carried down the script by default.

No comments:

Post a Comment