A contour plot connects points of equal value with lines, turning a two-variable function into a flat map of level curves like the elevation lines on a topographic map.
set xrange [-3:3]
set yrange [-3:3]
set isosamples 60, 60
set contour base
set cntrparam levels 12
unset surface
set view map
set title "Contour Map of exp(-x^2 - y^2)"
set xlabel "x"
set ylabel "y"
splot exp(-x**2 - y**2) with lines notitle
How the script works
The function exp(-x**2 - y**2) is a smooth hill peaking at 1 in the center and falling toward 0 at the edges, so its contours are concentric rings. set isosamples 60, 60 samples it on a fine grid, which is what makes the contour lines smooth.
set contour base asks gnuplot to draw contour lines projected onto the base plane. set cntrparam levels 12 controls how many level curves are drawn; the alternative form set cntrparam levels incremental 0.1, 0.1, 0.9 places levels at exact values (start, step, end) instead of a count.
unset surface is the key line for a pure contour map: it suppresses the wireframe surface itself, leaving only the contour lines. set view map then looks at the base plane straight from above, and the plot still uses splot because contours are computed in 3D space.
Run it online: Paste this script into the online terminal and run it — no install needed.
Variant to try
For a filled contour map, gnuplot 6.0 offers the pm3d route: add set pm3d at b and a palette, keep the contours, and plot with pm3d to color the bands between levels. To label the levels, switch to a two-step workflow: write the contour lines to a table file with set table, then plot that table in 2D — the standard technique when contour labels are required.
Related tutorials: 3D Plots with splot, Heatmaps in Gnuplot with pm3d. See more copy-and-run scripts in the Gnuplot Examples index.
Scripts on this page are adapted from the official gnuplot 6.0 demo collection (gnuplot.info) and rewritten for this tutorial.
