What Gnuplot is and how to get the latest build
Gnuplot is an open‑source, command‑line utility for generating 2‑D and 3‑D plots of data, mathematical functions, and statistical fits. The current stable release is 6.0.2 (Dec 2024) .
brew install gnuplot
— macOS (Homebrew)sudo apt install gnuplot
— Debian/Ubuntu
Note: Enable --with-qt
or --with-cairo
options at build time to unlock high‑quality PNG/SVG/PDF output.
Hello sine‑wave in one command
plot sin(x) title "Sine wave" with lines lw 2
The default interactive wxt
terminal opens a window showing the curve.
Close it or press q to return to the prompt.
Column formats, comments, and inline data
# x y y2 <‑‑ comments with '#'
0 0 0
1 0.8 0.2
2 1.0 0.4
#
or by using set datafile commentschars "
.
plot "-" u 1:2 w lp title "inline"
0 0
1 1
2 4
e
lines, points, histograms, pm3d, vectors …
plot "data.dat" u 1:2 w lines title "Lines"
replot "" u 1:3 w points pt 7 title "Points"
replot "" u 1:2:3 w errorbars title "Error"
set style data histogram
plot "hist.dat" u 2:xtic(1) title "Histogram"
Full style catalog in the Demos gallery .
Make your graph publication‑ready
set title "Damped oscillator"
set xlabel "time (s)"
set ylabel "amplitude (m)"
set xrange [0:10]
set yrange [-1:1]
set grid
Use set format x "%%.1f"
to control numeric formatting.
Multiseries, dual axes, heatmaps, filled‑curves
set y2tics
plot "temp.dat" u 1:2 w lp axes x1y1 title "°C", \
"power.dat" u 1:2 w lp axes x1y2 title "kW"
set palette rgb 33,13,10
plot "matrix.dat" matrix with image title "Heatmap"
From parametric surfaces to point clouds
set hidden3d
set pm3d depthorder
splot x*y with pm3d title "Surface"
splot "cloud.xyz" w points pt 7 palette title "Point cloud"
Toggle view with mouse‑drag if using the qt
terminal.
Levenberg‑Marquardt built in
f(x) = a*exp(-b*x) + c
a=1; b=0.5; c=0
fit f(x) "decay.dat" via a,b,c
plot "decay.dat" u 1:2 w p, f(x) lw 2 title sprintf("τ = %.2f", 1/b)
Initial parameter guesses matter; inspect the fit log in fit.log
.
Dashboards in a single canvas
set multiplot layout 2,2 title "Quarterly overview"
plot "q1.dat" w lp
plot "q2.dat" w lp
plot "q3.dat" w lp
plot "q4.dat" w lp
unset multiplot
Automate everything with *.gp files
#!/usr/bin/env gnuplot
reset
load "styles.gp"
data = ARG1
out = ARG2
set terminal pdfcairo size 4in,3in
set output out
plot data u 1:2 w lp title "Experiment"
Call via gnuplot script.gp "data.tsv" "result.pdf"
.
PNG, SVG, PDF, TikZ & interactive canvases
set terminal pngcairo size 1600,1200
set terminal svg font "Roboto,12"
set terminal qt
(interactive, scroll‑wheel zoom)
set output "figure.png"
Generate GIF/MP4 frames in a loop
set term gif animate delay 5 size 800,600
set output "wave.gif"
do for [p=0:360] {
plot sin(x+p/30.) w l notitle
}
unset output
Python, C, and shell pipes
subprocess
)
import subprocess, textwrap, os, shlex
gp_script = textwrap.dedent("""
set term pngcairo size 800,600
set output 'pyplot.png'
plot sin(x)
""")
subprocess.run(shlex.split("gnuplot -persist"), input=gp_script.encode())
FILE *gp = popen("gnuplot -persist", "w");
fprintf(gp, "plot 'data.dat' u 1:2 w lp\n");
pclose(gp);
Keep your scripts tidy and portable
reset
to avoid inherited settings.styles.gp
and load
it.set term tikz
.pause -1
at the end of scripts when debugging.Common error “all points undefined” → check that your using/expression indexes columns that exist.
Manuals, books, cheat‑sheets