4

I want to plot a surface plot in two parameters with pgfplots. A part of the surface which should appear behind the main surface as above it, which looks like a glitch. Plot with glitch. If I reverse the y axis, everything looks fine: Plot with reversed y axis and no glitch.

MWE:

\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}

\begin{document}
\begin{tikzpicture}
 \begin{axis}%[y dir=reverse]
  \addplot3[surf,mesh/ordering=y varies]
    table {glitch.dat};
 \end{axis}
\end{tikzpicture} 
\end{document}

Glitch.dat can be found here: http://pastebin.com/bEyyKSnz Is there a parameter to pass to pgfplots to avoid this?

  • 2
    You could check into the various possible settings of the z buffer key, described in Section 4.6.5 of the pgfplots manual. – Paul Gessler Oct 6 '14 at 18:00
  • Adding 'z buffer=sort' solved the problem! Thanks! Can you turn your comment into an answer so I can accept it? – mektah Oct 6 '14 at 18:07
9

For 3-dimensional plots, pgfplots uses z buffer=auto to try to determine the smartest way to paint the drawing with the correct patches on top. In this case, the auto method doesn't produce acceptable results.

Use z buffer=sort to correct the issue. The possibilities for z buffer are described in Section 4.6.5 of the current (v1.11) pgfplots manual.

\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}

\begin{document}
\begin{tikzpicture}
 \begin{axis}%[y dir=reverse]
  \addplot3[surf,mesh/ordering=y varies,z buffer=sort]
    table {glitch.dat};
 \end{axis}
\end{tikzpicture} 
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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