Gnuplot: Difference between revisions

From csml-wiki.northwestern.edu
Jump to navigation Jump to search
Line 15: Line 15:
Often when the output of a gnupot script requires further formatting it is easiest to do so using the [http://en.wikipedia.org/wiki/Encapsulated_PostScript Encapsulated PostScript] (EPS) terminal. This is essentially the same as the PostScript terminal except that it contains some extra lines that allow it to interface with other programs. Invoke the EPS terminal as follows:
Often when the output of a gnupot script requires further formatting it is easiest to do so using the [http://en.wikipedia.org/wiki/Encapsulated_PostScript Encapsulated PostScript] (EPS) terminal. This is essentially the same as the PostScript terminal except that it contains some extra lines that allow it to interface with other programs. Invoke the EPS terminal as follows:


<code>set term post eps [options]<br />set output filename.eps</code>
set term post eps [options]<br />set output filename.eps


For possible options see the instructions for the PostScript terminal on [http://www.gnuplotting.org/output-terminals/ this page]. To edit the resulting .eps file it is convenient to use [http://www.grymoire.com/unix/sed.html sed]. For example to change all instances of 0.0 to 0 one would use
For possible options see the instructions for the PostScript terminal on [http://www.gnuplotting.org/output-terminals/ this page]. To edit the resulting .eps file it is convenient to use [http://www.grymoire.com/unix/sed.html sed]. For example to change all instances of 0.0 to 0 one would use


<code>sed -i 's/(0.0)/(0)/g' filename.eps</code>
sed -i 's/(0.0)/(0)/g' filename.eps


Once you have your eps file exactly as you like it you can convert it to PDF format using epstopdf. Executing the command
Once you have your eps file exactly as you like it you can convert it to PDF format using epstopdf. Executing the command


<code>epstopdf filename.eps</code>
epstopdf filename.eps


will create the PDF file <code>filename.pdf</code>.
will create the PDF file <code>filename.pdf</code>.

Revision as of 12:50, 20 May 2014

Overview

Gnuplot is a program for plotting scientific data. The resulting figures can be of very high quality, provided that attention is paid to detail. Impressive examples can be found on the gnuplot homepage. This page does not provide a detailed manual for gnuplot, but instead focuses on specific aspects typically accounted in the CSML when creating figures for manuscripts.

PDF terminal

The version of gnuplot installed on all local machines has been compiled with PDFlib, which makes it possible to directly produce PDF images. Such figures offer the important advantage that they are fully scalable and yet have a small file size. Choose this terminal via

 set term pdf enh

Sometimes, fine-tuning of the resulting PDF figure is most conveniently done in Adobe Illustrator: each component of the figure will appear as an object that you can move, resize, etc.

Encapsulated PostScript terminal

Often when the output of a gnupot script requires further formatting it is easiest to do so using the Encapsulated PostScript (EPS) terminal. This is essentially the same as the PostScript terminal except that it contains some extra lines that allow it to interface with other programs. Invoke the EPS terminal as follows:

 set term post eps [options]
set output filename.eps

For possible options see the instructions for the PostScript terminal on this page. To edit the resulting .eps file it is convenient to use sed. For example to change all instances of 0.0 to 0 one would use

 sed -i 's/(0.0)/(0)/g' filename.eps

Once you have your eps file exactly as you like it you can convert it to PDF format using epstopdf. Executing the command

 epstopdf filename.eps

will create the PDF file filename.pdf.

Formatting labels

When choosing for instance an axis label via

set xlabel "x Label"

it is straightforward to use simple text, however often special formatting is necessary. A brief set of rules follows. For italic script place

{/Helvetica-Italic [text]}

inside the quotes, where [text] is what you wish to have in italics. All variables should be in italics. For greek letters use

{Symbol [text]}

where [text] is any character off of the list linked here. For italic Greek characters use

{Symbol-Oblique [text]}

More instructions are available here.

Sample usage script

The following is a sample gnuplot script. Everything in braces should be replaced. Again, see the gnuplot homepage or appropriate tutorial for more comprehensive usage.

set term post eps enh color {dashed|solid} lw 2
set output "filename.eps"
set encoding iso_8859_1
set key top right
set format x "%3.2f" #format tics to have max 3 digits and
set format y "%3.2f" #max 2 digits after the decimal
set xlabel "{xLabel}"
set ylabel "{yLabel}"
set xrange [{xmin}:{xmax}]
set yrange [{ymin}:{ymax}]
plot "datafile.dat" using 1:2:3 with errorbars

General usage tips

  • Journals typically prefer Helvetica as the typeface for figures.