# Parametric surface

> A torus drawn from its parametric equations, shaded by height. A pgfplots example with its complete LaTeX source, ready to copy or open in TeXeR.

A pgfplots example in the TeXeR TikZ library: https://texer.org/library/pgfplots/torus-surface

Package: [pgfplots](https://texer.org/library/pgfplots.md), on CTAN at https://ctan.org/pkg/pgfplots.

Tags: 3D, surface, parametric, torus

## Source

```latex
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{tikzpicture}
  \begin{axis}[
    width=9cm, view={35}{40}, axis equal image, hide axis,
    colormap/cool, z buffer=sort,
  ]
    \addplot3[surf, shader=faceted interp, samples=36, samples y=18,
      domain=0:360, domain y=0:360, line width=0.1pt]
      ({(2 + cos(y))*cos(x)}, {(2 + cos(y))*sin(x)}, {sin(y)});
  \end{axis}
\end{tikzpicture}
```

## As a complete document

The same example in a document that compiles on its own with pdfLaTeX:

```latex
\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}

\begin{tikzpicture}
  \begin{axis}[
    width=9cm, view={35}{40}, axis equal image, hide axis,
    colormap/cool, z buffer=sort,
  ]
    \addplot3[surf, shader=faceted interp, samples=36, samples y=18,
      domain=0:360, domain y=0:360, line width=0.1pt]
      ({(2 + cos(y))*cos(x)}, {(2 + cos(y))*sin(x)}, {sin(y)});
  \end{axis}
\end{tikzpicture}
\end{document}
```
