Saddle point surface in pgfplots, explained
Quick answer
This figure plots the saddle F = V² − T² as a 3D surface: it curves up along V and down along T, with the saddle point at the centre. It takes three lines of pgfplots: an axis with samples=30 and no ticks, and one \addplot3[surf] of the expression x^2-y^2 over −2 to 2 in both directions. Instead of the usual colormap, every face is the same DarkBlue at 50% opacity with black grid lines, which gives the translucent, wire-framed look.
Contents
The figure and its code

% Saddle point surface
% Source: https://github.com/janosh/diagrams/blob/7a79b3114e201fad9b6785e936eab859d1bc8c12/assets/saddle-point/saddle-point.tex
% Copyright (c) 2021 Janosh Riebesell. MIT licence: https://github.com/janosh/diagrams/blob/main/license
% The licence’s copyright and permission notice: https://www.labcanvas.com/tikz-library/credits.html
\documentclass[svgnames]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[samples=30,ticks=none,xlabel={$V$},ylabel={$T$},zlabel={$F(T,V)$}]
\addplot3[surf,color=DarkBlue,opacity=0.5,domain=-2:2,faceted color=black] {x^2-y^2};
\end{axis}
\end{tikzpicture}
\end{document}
A colour name from the class options
Lines 5–8 of the code
\documentclass[svgnames]{standalone} passes svgnames to every package that accepts it, which is how class options work in LaTeX. Here it reaches xcolor (loaded by TikZ through pgfplots) and switches on its extended list of colour names, such as DarkBlue, Tomato or SeaGreen. Without that option, color=DarkBlue below would be an undefined colour. pgfplots is the only package, and compat=newest asks for the newest behaviour of whichever pgfplots version compiles the file; the variations pin compat=1.18 so that their output does not change with an update.
An axis without ticks
Line 13 of the code
The options of the axis environment set three things. samples=30 is the number of points per direction: for a 3D expression plot, samples y takes the same value when it is not set, so the surface is a 30 × 30 grid of points, 29 × 29 faces. ticks=none removes all tick marks and tick labels, because the figure illustrates a shape, not values. The three labels, including zlabel={$F(T,V)$}, name the axes; the axis becomes three-dimensional because the plot inside it is an \addplot3, and it is seen from pgfplots’ default viewpoint, 25° azimuth and 30° elevation.
One surface plot
Line 15 of the code
\addplot3[…] {x^2-y^2}; samples the expression over a grid of x and y. domain=-2:2 sets the x range; the y range, y domain, is empty, and pgfplots then uses the x range for y as well, so the grid covers the square from −2 to 2. x is V and y is T: at the centre the surface has a minimum along V and a maximum along T, the defining property of a saddle point.
surf fills each grid cell. By default it colours each face from the colormap according to its height (it installs color=mapped color); giving color=DarkBlue among the plot’s options overrides that, so every face has the same colour. opacity=0.5 makes the faces half transparent, which lets the back of the surface show through and lightens the dark blue. faceted color=black draws the grid lines between the faces in black instead of the default, a darker shade of each face’s own colour. The default shader, faceted, gives each face one flat colour; the first variation uses shader=interp for smooth shading instead.
Techniques used
- 3D surface plots with pgfplots
\addplot3[surf]of an expression in x and y, withdomainandsamples. - Colours and opacity xcolor’s
svgnameslist, a single fill colour andopacity=0.5. - Colormaps the default height-based colouring, overridden here and used in the variations (
colormap/viridis). - Physics diagrams schematic thermodynamic surfaces and potentials in physics figures.
Variations
Our own code, written for this page and typeset with TeX Live 2026 like the figure above. Each one is a complete example: copy it, or open it in the TikZ editor and change it. This code is CC0 1.0, free to use without conditions.
Coloured by height, with smooth shading and the saddle point
The more common style: no fixed colour, so surf colours the surface by height through colormap/viridis (a colour-blind-friendly map that also prints well in grey), shader=interp blends the colours smoothly across each face, and colorbar adds the scale. A different viewpoint, view={-35}{25}, shows both the rising and the falling direction. The saddle point is a second plot with one marker, drawn after the surface so that it stays visible.

\usepackage{tikz} \usepackage{pgfplots} \pgfplotsset{compat=1.18}\begin{tikzpicture}
\begin{axis}[
view={-35}{25}, colormap/viridis, colorbar,
domain=-2:2, samples=31,
xlabel={$V$}, ylabel={$T$}, zlabel={$F$},
xtick={-1,0,1}, ytick={-1,0,1}, ztick={-4,0,4},
]
% colour from the height: surf uses the colormap unless a colour is given
\addplot3[surf, shader=interp] {x^2 - y^2};
% the saddle point itself, drawn after the surface so it stays visible
\addplot3[only marks, mark=*, mark size=2.5pt, red] coordinates {(0,0,0)};
\end{axis}
\end{tikzpicture}
Full document
\documentclass[border=4pt]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
view={-35}{25}, colormap/viridis, colorbar,
domain=-2:2, samples=31,
xlabel={$V$}, ylabel={$T$}, zlabel={$F$},
xtick={-1,0,1}, ytick={-1,0,1}, ztick={-4,0,4},
]
% colour from the height: surf uses the colormap unless a colour is given
\addplot3[surf, shader=interp] {x^2 - y^2};
% the saddle point itself, drawn after the surface so it stays visible
\addplot3[only marks, mark=*, mark size=2.5pt, red] coordinates {(0,0,0)};
\end{axis}
\end{tikzpicture}
\end{document}Seen from above, with level lines
The same function as a heat map: view={0}{90} looks straight down, and axis equal image keeps the square square. A second \addplot3 with contour lua computes the level lines F = −3 … 3 and draws them in black. contour lua needs LuaLaTeX, which is why this snippet is compiled with it; the crossing lines at F = 0 through the centre are the signature of a saddle point.

\usepackage{tikz} \usepackage{pgfplots} \pgfplotsset{compat=1.18}Compile with LuaLaTeX\begin{tikzpicture}
\begin{axis}[
view={0}{90}, axis equal image, colormap/viridis, colorbar,
domain=-2:2, samples=41, xlabel={$V$}, ylabel={$T$},
title={$F = V^2 - T^2$ seen from above},
]
\addplot3[surf, shader=interp] {x^2 - y^2};
% contour lua computes the level lines (it needs LuaLaTeX)
\addplot3[contour lua={levels={-3,-2,-1,0,1,2,3}, labels=false, draw color=black},
thick] {x^2 - y^2};
\end{axis}
\end{tikzpicture}
Full document
\documentclass[border=4pt]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
view={0}{90}, axis equal image, colormap/viridis, colorbar,
domain=-2:2, samples=41, xlabel={$V$}, ylabel={$T$},
title={$F = V^2 - T^2$ seen from above},
]
\addplot3[surf, shader=interp] {x^2 - y^2};
% contour lua computes the level lines (it needs LuaLaTeX)
\addplot3[contour lua={levels={-3,-2,-1,0,1,2,3}, labels=false, draw color=black},
thick] {x^2 - y^2};
\end{axis}
\end{tikzpicture}
\end{document}Frequently asked questions
How do I plot a 3D surface in LaTeX?
Load pgfplots and write \begin{axis} \addplot3[surf, domain=-2:2, samples=30] {x^2-y^2}; \end{axis} inside a tikzpicture. The y range defaults to the x range; set y domain=… for a different one.
How do I give a pgfplots surface a single colour?
Give the colour among the plot’s options, \addplot3[surf, color=blue!60] {…};. surf normally colours the faces from the colormap; an explicit colour replaces that. Add opacity=0.5 for a see-through surface and faceted color=black for black grid lines.
How do I add contour lines to a pgfplots surface?
Add a second plot with \addplot3[contour lua={levels={-1,0,1}}] {…}; and compile with LuaLaTeX. Without LuaLaTeX, contour gnuplot needs gnuplot and shell escape.
References
- janosh/diagrams at commit 7a79b31: assets/saddle-point/saddle-point.tex (MIT licence)github.com
- pgfplots manual, §4.6.2 The \addplot3 Command: Three Dimensional Coordinate Input (domain, y domain, samples y)tikz.dev
- pgfplots manual, §4.6.5 Mesh Plots and §4.6.6 Surface Plots (shader, faceted color)tikz.dev
- pgfplots manual, §4.6.8 Contour Plots (contour lua)tikz.dev
- pgfplots manual, §4.7.6 Color Maps (viridis)tikz.dev
- pgfplots manual, §4.11.1 View Configurationtikz.dev
- pgfplots manual (v1.18.3), §2.2 Upgrade remarks (the compat key)mirrors.ctan.org
- xcolor package on CTAN (manual: the svgnames option and its colour names)ctan.org
The walkthrough was checked against these sources and the pictures are the code typeset with TeX Live 2026. The original figure is © Janosh Riebesell and contributors, under the MIT licence; the variations on this page are ours, CC0 1.0.
Change this figure in your browserOpen the figure or any variation in the free TikZ editor: it is typeset with TeX Live as you type, with errors pointed at their line.
Open the figure in the TikZ editor