# Clipping a 3D plot with pgfplots

How can I clip the paths of a 3D plot to the 3D axis bounding box? I am not talking about clipping the path to the projection of the bounding box (which pgfplots does by default), I want to remove points that lie outside the box in 3D.

Consider the following plot:

\documentclass{standalone}
\usepackage{tikz, pgfplots}
\pgfplotsset{compat = 1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xmin = -1.1, xmax = 1.1,
ymin = -1.1, ymax = 1.1,
zmin = -1.1, zmax = 1.1]
samples y = 0, very thick] (0, 0, {2 * x});
\end{axis}
\end{tikzpicture}
\end{document}


What I want (without changing the plot formula), is this:

Note that markers are clipped to the box: change \addplot3 to \addplot3+, and markers will appear on the part inside the box, but not on the part outside.

I tried various clip options from the manual, but so far nothing I tried was successful.

You can use the restrict z to domain key. It can be applied for the entire axis or per-plot, whichever you require.

\documentclass{standalone}
\usepackage{tikz, pgfplots}
\pgfplotsset{compat = 1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xmin = -1.1, xmax = 1.1,
ymin = -1.1, ymax = 1.1,
zmin = -1.1, zmax = 1.1]

• Great! Now that I know what it is called, a note to future readers: restrict x to domain and restrict y to domain also exist. – Ruud Jun 26 '15 at 22:30