[Tex/LaTex] How to remove coordinates in a 3d plot using pgfplots

3dpgfplots

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]
\addplot3[surf,mesh/rows=3,shader=flat,draw=black] coordinates {
(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?

Best Answer

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]
\addplot3[surf,mesh/rows=3,shader=flat,unbounded coords=jump,draw=black] 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}

\begin{tikzpicture}
\begin{axis}[clip=false,view={45}{45},grid=major]
\addplot3[surf,unbounded coords=jump,shader=flat,draw=black] coordinates {
(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}

enter image description here

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.