# Saddle point surface in pgfplots, explained

> How a 3D saddle surface F = V² − T² is plotted with pgfplots \addplot3 surf: samples, colour, opacity, grid lines, plus colormap and contour variations.

URL: https://www.labcanvas.com/tikz/examples/mathematics/saddle-point-surface

Updated 2026-11-22. Original figure: Saddle point surface, © Janosh Riebesell and contributors, MIT licence (licence text: https://www.labcanvas.com/tikz-library/credits.html#janosh), from https://github.com/janosh/diagrams/blob/7a79b3114e201fad9b6785e936eab859d1bc8c12/assets/saddle-point/saddle-point.tex. Walkthrough and variations by LabCanvas; the variation code is CC0 1.0 (https://creativecommons.org/publicdomain/zero/1.0/). Pictures typeset with TeX Live 2026 and PGF 3.1.12. Category: [TikZ mathematics examples](https://www.labcanvas.com/tikz/examples/mathematics).

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

## The figure and its code

![A 3D surface plot in a box with axes labelled V, T and F(T,V) and no tick marks: a translucent dark blue saddle with a black grid, rising towards the two ends along V and falling towards the two ends along T.](https://www.labcanvas.com/tikz-snippets/fig-saddle-point-surface/original.webp)

Copyright (c) 2021 Janosh Riebesell, MIT licence (https://www.labcanvas.com/tikz-library/credits.html#janosh). The code below is exactly the library's file (pdfLaTeX); its first lines name the source and the licence, and the MIT licence asks that they stay with the code. Open it in the TikZ editor from the page: https://www.labcanvas.com/tikz/examples/mathematics/saddle-point-surface

```latex
% 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](https://www.labcanvas.com/tikz/plots): `\addplot3[surf]` of an expression in x and y, with `domain` and `samples`.
- [Colours and opacity](https://www.labcanvas.com/tikz/colors): xcolor’s `svgnames` list, a single fill colour and `opacity=0.5`.
- [Colormaps](https://www.labcanvas.com/tikz/colors): the default height-based colouring, overridden here and used in the variations (`colormap/viridis`).
- [Physics diagrams](https://www.labcanvas.com/tikz/physics-diagrams): schematic thermodynamic surfaces and potentials in physics figures.

## Variations

Our own code, CC0 1.0, each typeset with TeX Live 2026 in a standalone document with the preamble lines shown.

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

![A 3D saddle surface shaded smoothly from dark purple at the lowest corners through teal to yellow at the highest, axes labelled V, T and F with ticks at −1, 0 and 1, a colour bar on the right and a red dot at the centre of the saddle.](https://www.labcanvas.com/tikz-snippets/fig-saddle-point-surface/viridis-saddle.webp)

*the saddle coloured by height with the viridis colormap, smooth shading and the saddle point in red*

Preamble: `\usepackage{tikz}`, `\usepackage{pgfplots}`, `\pgfplotsset{compat=1.18}`

```latex
\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}
```

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

![A square heat map of F = V² − T² seen from above, yellow towards the left and right edges and purple towards the top and bottom, with black hyperbola-shaped level lines and two straight level lines crossing in an X at the centre, and a colour bar on the right.](https://www.labcanvas.com/tikz-snippets/fig-saddle-point-surface/contours-from-above.webp)

*the saddle from above as a heat map with black level lines F = −3 to 3 (LuaLaTeX)*

Preamble: `\usepackage{tikz}`, `\usepackage{pgfplots}`, `\pgfplotsset{compat=1.18}` (compile with LuaLaTeX)

```latex
\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}
```

## 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)](https://github.com/janosh/diagrams/blob/7a79b3114e201fad9b6785e936eab859d1bc8c12/assets/saddle-point/saddle-point.tex)
- [pgfplots manual, §4.6.2 The \addplot3 Command: Three Dimensional Coordinate Input (domain, y domain, samples y)](https://tikz.dev/pgfplots/reference-3dplots#sec-4.6.2)
- [pgfplots manual, §4.6.5 Mesh Plots and §4.6.6 Surface Plots (shader, faceted color)](https://tikz.dev/pgfplots/reference-3dplots#sec-4.6.6)
- [pgfplots manual, §4.6.8 Contour Plots (contour lua)](https://tikz.dev/pgfplots/reference-3dplots#sec-4.6.8)
- [pgfplots manual, §4.7.6 Color Maps (viridis)](https://tikz.dev/pgfplots/reference-markers#sec-4.7.6)
- [pgfplots manual, §4.11.1 View Configuration](https://tikz.dev/pgfplots/reference-3dconfiguration#sec-4.11.1)
- [pgfplots manual (v1.18.3), §2.2 Upgrade remarks (the compat key)](https://mirrors.ctan.org/graphics/pgf/contrib/pgfplots/doc/pgfplots.pdf)
- [xcolor package on CTAN (manual: the svgnames option and its colour names)](https://ctan.org/pkg/xcolor)

## TikZ guides for these techniques

- [TikZ plots with pgfplots: functions, data, scatter, bars and 3D](https://www.labcanvas.com/tikz/plots): Plot in LaTeX with pgfplots: functions, data tables, scatter plots coloured by value, error bars, bar charts, log axes, 3D surfaces and groupplots.
- [TikZ colors: names, mixing, fill, shading and patterns](https://www.labcanvas.com/tikz/colors): TikZ colours with xcolor: every named colour (base and dvipsnames charts), red!30 mixing, custom colours, fill and filldraw, opacity, shading, patterns.
- [TikZ physics diagrams: forces, springs, optics, waves and fields](https://www.labcanvas.com/tikz/physics-diagrams): Physics diagrams in TikZ with code: free-body diagram, inclined plane, spring and pendulum, a lens ray diagram, waves, energy levels and a dipole field.
