# Glitch in 3D surface plot using pgfplots

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. If I reverse the y axis, everything looks fine:

MWE:

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

\begin{document}
\begin{tikzpicture}
\begin{axis}%[y dir=reverse]
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?

• 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

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]