A pm3d surface plot colors a 3D surface by height, so peaks and valleys are visible both from the shape and from the color at the same time.
set pm3d at s
set palette rgbformulae 33,13,10
set hidden3d
set isosamples 50, 50
set xrange [-3:3]
set yrange [-3:3]
set xlabel "x"
set ylabel "y"
set zlabel "z"
set title "pm3d Surface: sin(x) * cos(y) * exp(-0.1 * (x^2 + y^2))"
set colorbox
set view 60, 30, 1, 1
splot sin(x) * cos(y) * exp(-0.1 * (x**2 + y**2)) with pm3d notitle
How the script works
set pm3d at s enables palette-mapped 3D drawing and places the colored surface at the surface position (s). Combined with with pm3d in the splot command, each facet of the sampled grid is filled with a color taken from the palette according to its z value, and pm3d sorts the facets by depth so nearer parts correctly cover farther parts.
set palette rgbformulae 33,13,10 selects a classic rainbow-style palette by formula numbers; gnuplot has many built-in options here, and test palette in an interactive session previews them. set colorbox draws the color legend bar so readers can map colors back to values.
set hidden3d keeps hidden-line removal active for any line elements drawn with the surface, and set isosamples 50, 50 sets the grid density: 50 sample lines per direction gives a smooth surface for this gentle function without slowing the render. set view 60, 30, 1, 1 fixes the viewing angle (elevation 60, azimuth 30).
Run it online: Paste this script into the online terminal and run it — no install needed.
Variant to try
For a surface over measured grid data instead of a function, keep every setting and replace the function with a file: splot "grid.dat" matrix with pm3d notitle for matrix data, or splot "points.dat" using 1:2:3 with pm3d after a set dgrid3d resampling pass for scattered xyz points. A monochrome print variant swaps the palette line for set palette gray.
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.
