1 | Introduction & Installation

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) .

Quick install

  1. brew install gnuplot — macOS (Homebrew)
  2. sudo apt install gnuplot — Debian/Ubuntu
  3. Windows: download the official installer from gnuplot.info

Note: Enable --with-qt or --with-cairo options at build time to unlock high‑quality PNG/SVG/PDF output.

2 | Your First Plot

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.

3 | Data Files

Column formats, comments, and inline data

Tabular files


# x  y  y2   <‑‑ comments with '#'
 0  0   0
 1  0.8 0.2
 2  1.0 0.4
		
  1. Column delimiter auto‑detected (whitespace/CSV/TSV).
  2. Skip meta‑lines with # or by using set datafile commentschars ".

Inline data blocks


plot "-" u 1:2 w lp title "inline"
0 0
1 1
2 4
e
		

4 | Plot Styles

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 .

5 | Axes, Ranges & Labels

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.

6 | Advanced 2‑D Techniques

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"
		

7 | 3‑D Plotting

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.

8 | Functions & Curve‑Fitting

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.

9 | Multiplot Layouts

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
		

10 | Scripting & Macros

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".

11 | Output Terminals

PNG, SVG, PDF, TikZ & interactive canvases

  1. set terminal pngcairo size 1600,1200
  2. set terminal svg font "Roboto,12"
  3. set terminal qt (interactive, scroll‑wheel zoom)

set output "figure.png"
		

12 | Animation

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
		

13 | Gnuplot from Other Languages

Python, C, and shell pipes

Python (with 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())
		

C (pipe)


FILE *gp = popen("gnuplot -persist", "w");
fprintf(gp, "plot 'data.dat' u 1:2 w lp\n");
pclose(gp);
		

14 | Tips, Best Practices & Troubleshooting

Keep your scripts tidy and portable

  1. Always start with reset to avoid inherited settings.
  2. Bundle repeated styling commands into styles.gp and load it.
  3. For LaTeX integration, output set term tikz.
  4. Use pause -1 at the end of scripts when debugging.

Common error “all points undefined” → check that your using/expression indexes columns that exist.

15 | Resources & Further Reading

Manuals, books, cheat‑sheets

  1. Official manual (PDF)  — 6.x series
  2. Online reference & demo gallery
  3. Gnuplot in Action, 2nd ed. (Manning)
  4. gnuplotting.org tutorials