Three-dimensional plots in gnuplot use splot, the 3D sibling of plot: give it a function of x and y (or a data grid) and it draws a surface. The script below renders z = sin(x)·cos(y) as a hidden-line surface.
set hidden3d
set isosamples 40, 40
set xlabel "x"
set ylabel "y"
set zlabel "z"
set title "z = sin(x) * cos(y)"
set view 60, 30, 1, 1
splot sin(x) * cos(y) with lines notitle
What each part does
splot sin(x) * cos(y) evaluates the function over the default x and y ranges (-10 to 10 each — narrow them with set xrange and set yrange for a tighter view). set isosamples 40, 40 controls the mesh density: 40 sample lines in each direction. Too few samples make a coarse, angular surface; too many slow rendering and clutter a wireframe.
set hidden3d removes the parts of the mesh that would be hidden behind the surface, which is what makes the result read as a solid object instead of a transparent net. The viewpoint comes from set view 60, 30, 1, 1: the first number is the rotation around the x axis (viewing elevation, 0–90 for above the plane), the second is the rotation around the z axis (azimuth), and the last two are a scale and a z-scale factor. In an interactive terminal you can also drag the plot with the mouse to find an angle, then read the matching numbers back from the view settings.
Variants and going further
For a colored surface instead of a wireframe, switch the style to pm3d: set pm3d at s, pick a palette such as set palette rgbformulae 33,13,10, and plot with splot sin(x) * cos(y) with pm3d notitle. The at s puts the colored surface on top of the grid. Data works the same way as functions: splot "grid.dat" with lines for xyz or matrix data, and adding set contour base projects contour lines onto the floor of the plot — a combination that reads well in print.
Common mistakes
- Surface looks like a flat net with no depth:
set hidden3dis off or the view angle is degenerate (for example elevation 0). Keep hidden3d on for wireframes and start fromset view 60, 30before fine-tuning. - Jagged, low-poly surface:
isosamplesis too low for the function’s detail. Raise it (40–80 per direction is typical) — but for pm3d surfaces, preferset isosamplesplusset pm3d interpolatecautiously, since interpolation smooths color, not geometry.
Related tutorials: Heatmaps with pm3d, Multiplot Layouts. See also the full Gnuplot Tutorials index.
Try it online: The online terminal renders splot surfaces too, so you can test view angles before committing to a script. Paste the script into the Gnuplot Online terminal and run it in your browser — no install needed. To run gnuplot locally instead, see the installation guide and the download page.
Go deeper: For a systematic walk through gnuplot from first plots to publication-ready figures, see Gnuplot in Action by Philipp K. Janert — Janert is a gnuplot developer, and the book is the most complete tutorial reference for the program. Affiliate link: see our Affiliate Disclosure.
