Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
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} –  user12876 Mar 23 '12 at 13:11
add comment

1 Answer

up vote 6 down vote accepted

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.

share|improve this answer
1  
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. –  user12876 Mar 23 '12 at 18:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.