Lore Michael Lones

Gnuplot Tricks and Tips

Gnuplot is undoubtedly a powerful tool, but getting it to do what you want can be a considerable challenge. This collection of tricks and tips reflects my ongoing struggle to get Gnuplot to do what I want.

PDF Output

These commands will cause a plot to be saved as a suitably-sized PDF file. Note that this approach requires that epstopdf is installed and on your unix path. You can also use Gnuplot's pdf terminal for PDF output, though getting it to set a plot-sized bounding box may be a challenge!

set terminal postscript eps
set output '| epstopdf --filter --outfile=plot.pdf'

Changing line styles

With earlier versions of Gnuplot, you were limited to using predefined line styles (i.e. colours and markers), but these could be re-ordered, e.g.:

set style line 1 linetype 2
plot x ls 1

More recent versions allow greater flexibility, e.g:

plot x linecolor rgb "blue" linewidth 2 pointtype 4 pointsize 2

or, more succinctly:

plot x lc rgb "blue" lw 2 pt 4 ps 2

ROC plot

To draw a ROC plot with balanced axis and suitable bounding box:

set size .75,1
set size ratio 1
set xtics .1
set ytics .1
set grid
set xrange [0:1.025]
set yrange [0:1.025]
set key right bottom
set ylabel "True Positive Rate"
set xlabel "False Positive Rate"


Since there is no modulus function in Gnuplot, you have to do it the hard way:

plot x-(floor(x/5)*5) title "x mod 5"

Using row and column labels (4.2 and later)

To use the first row of a data file for the legend:

plot "data.txt" title column

To use the first column of a data file for the x axis labels:

plot "data.txt" using 2:xticlabels(1)

Remember to double-quote any titles that contain spaces.

Greek symbols

This depends upon which terminal you are using. For the postscript terminal, use {/Symbol s}, where 's' is the Roman equivalent. There's a list here. Note that the postscript terminal must be in 'enhanced' mode for this to work. For example, lower case 'theta' with a subscript used for the x-axis label:

set terminal postscript eps enhanced
set xlabel "{/Symbol q}_{n+1}"

Command line arguments

Command line arguments can be passed to Gnuplot scripts, but the syntax is a little messy, e.g.:

echo "call \"gnuscript.txt\" \"'.'\" \"'data.dat'\"" | gnuplot

The arguments are received in the script using bash-like syntax:

PATH = $0

The values can then be used at any point within the script, so long as they're not contained within quotation marks, e.g.:


(Note that periods are used for string concatenation in Gnuplot)

These web pages use Google Analytics to track visits. See Privacy Statement.
© Michael Lones 2005-2016. Page last updated 30th October, 2013.