Quick Reference Guide
Quick Guide to GNUPlot
A practical reference for using GnuPlot to generate EPS, PNG, and PDF output — particularly for inclusion in LaTeX documents. Most commands require GnuPlot 3.7 or above. Current stable release is 6.0.
Note: This guide was originally published in 2006 and has been updated in May 2026 with additional sections and improved formatting, with assistance from Claude (Anthropic).
Setup
To plot a graph, create two files in the same directory:
| File | Purpose |
data.txt | Columns of values to be plotted, whitespace-separated. Lines beginning with # are treated as comments. |
plot.txt | GNUPlot commands that define the graph |
To generate the graph, run:
gnuplot plot.txt
Basic plot Command
The core command reads a data file and plots specified columns. Column indices are 1-based:
plot "data.txt" using 1:2 with lines title "My Data"
To plot multiple datasets on the same graph, separate them with a comma:
plot "data1.txt" using 1:2 with lines title "Series A", \
"data2.txt" using 1:2 with linespoints title "Series B"
| Style keyword | Description |
lines | Connect data points with lines |
points | Plot data as discrete markers |
linespoints | Both lines and markers |
boxes | Bar chart style |
Output Terminals
Set the terminal type before setting the output file. Use pngcairo or pdfcairo for modern conference submissions — they produce sharper output than the older drivers.
| Terminal | Command | Use case |
| EPS | set terminal postscript eps enhance 16 | LaTeX inclusion via \includegraphics |
| PNG | set terminal pngcairo size 800,600 | Web, slides, reports |
| PDF | set terminal pdfcairo | Conference paper submissions |
| SVG | set terminal svg | Scalable web graphics |
Always pair a terminal change with an output file and a fresh plot:
set terminal pngcairo size 800,600
set output "output.png"
plot "data.txt" using 1:2 with lines title "My Data"
Labels, Title and Grid
set title "Graph Title"
set xlabel "X Axis Label"
set ylabel "Y Axis Label"
set grid
set grid adds a light background grid — useful for readability in academic figures.
Axes — Range, Scale and Tickmarks
Set axis range
set xrange [0:50]
set yrange [0:100]
Logarithmic scale
Common for performance graphs and complexity curves:
set logscale x
set logscale y
set logscale xy # both axes
Remove mirror tickmarks
set xtics nomirror
set ytics nomirror
Preset tickmark positions on X axis
set xtics (10, 100, 1000, 10000)
# Can be combined: set xtics (10,100,1000,10000) nomirror
Line and Point Styles
Style modifiers can be appended inline to any plot command:
plot "data.txt" using 1:2 with linespoints \
lw 2 lt 1 pt 7 lc rgb "#2980b9" title "Result"
| Modifier | Meaning | Example |
lw | Line width | lw 2 |
lt | Line type (dash pattern) | lt 2 |
pt | Point type (marker shape) | pt 7 (filled circle) |
ps | Point size | ps 2 |
lc rgb | Line/point colour (hex) | lc rgb "#e74c3c" |
Use set pointsize 2 to set a global default point size, or set size 5,5 to change the overall plot dimensions.
Legend (Key) Placement
To move the legend to a specific coordinate (e.g. x=3, y=4):
set key 3, 4
Or use named positions:
set key top left
set key bottom right
set key off # hide legend entirely
Superscript, Subscript and Greek Symbols
Enhanced PostScript mode must be enabled in plot.txt for these to work. Change 16 to your desired font size:
set terminal postscript eps enhance 16
Superscript and Subscript
Use braces to group multiple characters:
| Effect | Syntax | Result |
| Subscript | P_{xyz} | P with xyz as subscript |
| Superscript | P^{xyz} | P with xyz as superscript |
Overbar and Underbar
There is no native overbar/underbar option in PostScript, but it can be simulated:
| Effect | Short | Long |
| Overbar on G | @^{\261}G | @^{\320}G |
| Underbar on G | @_{\261}G | @_{\320}G |
Greek Symbols
Use the {/Symbol ...} syntax:
| Symbol | Syntax |
| α (alpha) | {/Symbol a} |
| π (pi) | {/Symbol p} |
| λ (lambda) | {/Symbol l} |
For the full symbol list, see the PostScript guide PDF from the GNUPlot installation directory. Note: versions 3.5 and earlier do not support these PostScript options.
For full documentation, refer to the official GNUPlot website or run help from within the GNUPlot interactive prompt.