# How to remove coordinates in a 3d plot using pgfplots

I would like to know how to remove coordinates in an addplot3 surf plot. Here is a simplified example:

\begin{tikzpicture}
\begin{axis}[clip=false,view={45}{45},grid=major]
(1,1,0)(1,2,5)(1,3,7)
(2,1,0)(2,2,0)(2,3,4)
(3,1,0)(3,2,0)(3,3,0)};
\addplot3 coordinates {(1,1,0) (3,3,0)};
\end{axis}
\end{tikzpicture}


The part I want to remove is below the red line (because in my application, the matrix is symmetric and this part doesn't add any information). In Matlab, I can do this by using NaNs for z-values in the surf plot, because Matlab will not plot the NaNs. Is there a way to do this with pgfplots?

• pgfplots also detects nan values. Look for unbounded coords key in the manual. – percusse Mar 23 '12 at 12:50
• I tried, but then I get a weird surf plot:\begin{tikzpicture} \begin{axis}[ clip=false, view={45}{45}, grid=major] \addplot3[surf,mesh/rows=3,shader=flat,draw=black,unbounded coords=discard] coordinates { (1,1,0)(1,2,5)(1,3,7) (2,1,nan)(2,2,0)(2,3,4) (3,1,nan)(3,2,nan)(3,3,0)}; \addplot3 coordinates {(1,1,0) (3,3,0)}; \end{axis} \end{tikzpicture} – drl Mar 23 '12 at 13:11

The default configuration of unbounded coords=discard which will silently discard input coordinates as if they have not appeared at all.

What you need is unbounded coords=jump: in this case, each patch with an unbounded coordinate will be tracked, but not drawn at all:

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=1.5}

\begin{document}
\thispagestyle{empty}

\begin{tikzpicture}
\begin{axis}[clip=false,view={45}{45},grid=major]
(1,1,0)(1,2,5)(1,3,7)
(2,1,nan)(2,2,0)(2,3,4)
(3,1,nan)(3,2,nan)(3,3,0)};
\addplot3 coordinates {(1,1,0) (3,3,0)};
\end{axis}
\end{tikzpicture}

\begin{tikzpicture}
\begin{axis}[clip=false,view={45}{45},grid=major]
(1,1,0)(1,2,5)(1,3,7)

(2,1,0)(2,2,0)(2,3,4)

(3,1,nan)(3,2,0)(3,3,0)};
\addplot3 coordinates {(1,1,0) (3,3,0)};
\end{axis}
\end{tikzpicture}
\end{document}


So, what you need is to get a smaller resolution in order to resolve your wholes.

Maybe patch type=triangle would be a good idea as well since you have a diagonal cut - but you would need to adjust the input format of you coordinates accordingly.

• Indeed, using triangular and rectangular patches is actually simpler then with surf. The result is also better, since there is no hole in the surface. – drl Mar 23 '12 at 18:50