I have a PGFplots axis environment in which I attempt to plot several line objects and a surface object.
The objects have to be 'sorted' in the sense of which object is drawn before or behind the other.
The z buffer
key from PGFplots is supposed to resolve this, but I cannot seem to get it to work properly.
Depending on the order of the objects in the script, the surface object makes the line objects dissappear or the line objects are just shown on top of the surface object while they're supposed to be behind.
How do I solve this?
Minimum working example:
\documentclass{standalone}
\usepackage{filecontents}
\begin{filecontents}{3ddata.dat}
0 0 0
0.125 0 0
0.25 0 0
0.375 0 0
0.5 0 0
0.5 0 0
0.625 0 0
0.75 0 0
0.875 0 0
1 0 0
0 0.125 0.25
0.125 0.125 0.1875
0.25 0.125 0.125
0.375 0.125 0.0625
0.5 0.125 0
0.5 0.125 0
0.625 0.125 0
0.75 0.125 0
0.875 0.125 0
1 0.125 0
0 0.25 0.5
0.125 0.25 0.375
0.25 0.25 0.25
0.375 0.25 0.125
0.5 0.25 0
0.5 0.25 0
0.625 0.25 0
0.75 0.25 0
0.875 0.25 0
1 0.25 0
0 0.375 0.75
0.125 0.375 0.5625
0.25 0.375 0.375
0.375 0.375 0.1875
0.5 0.375 0
0.5 0.375 0
0.625 0.375 0
0.75 0.375 0
0.875 0.375 0
1 0.375 0
0 0.5 1
0.125 0.5 0.75
0.25 0.5 0.5
0.375 0.5 0.25
0.5 0.5 0
0.5 0.5 0
0.625 0.5 0
0.75 0.5 0
0.875 0.5 0
1 0.5 0
0 0.5 1
0.125 0.5 0.75
0.25 0.5 0.5
0.375 0.5 0.25
0.5 0.5 0
0.5 0.5 0
0.625 0.5 0
0.75 0.5 0
0.875 0.5 0
1 0.5 0
0 0.625 0.75
0.125 0.625 0.5625
0.25 0.625 0.375
0.375 0.625 0.1875
0.5 0.625 0
0.5 0.625 0
0.625 0.625 0
0.75 0.625 0
0.875 0.625 0
1 0.625 0
0 0.75 0.5
0.125 0.75 0.375
0.25 0.75 0.25
0.375 0.75 0.125
0.5 0.75 0
0.5 0.75 0
0.625 0.75 0
0.75 0.75 0
0.875 0.75 0
1 0.75 0
0 0.875 0.25
0.125 0.875 0.1875
0.25 0.875 0.125
0.375 0.875 0.0625
0.5 0.875 0
0.5 0.875 0
0.625 0.875 0
0.75 0.875 0
0.875 0.875 0
1 0.875 0
0 1 0
0.125 1 0
0.25 1 0
0.375 1 0
0.5 1 0
0.5 1 0
0.625 1 0
0.75 1 0
0.875 1 0
1 1 0
\end{filecontents}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
% Plot the function cuts at the boundary.
\addplot3 [color=red,solid] table {
0 0.5 0
0 0 1
0.5 0 0
};
\addplot3 [color=red,solid] table {
0 0 0
0.5 0 1
1 0 0
};
\addplot3 [color=red,solid] table {
0.5 0 0
1 0 1
1 0.5 0
};
\addplot3 [color=red,solid] table {
0 1 0
0 0.5 1
0 0 0
};
\addplot3 [color=red,solid] table {
1 0 0
1 0.5 1
1 1 0
};
\addplot3 [color=red,solid] table {
0.5 1 0
0 1 1
0 0.5 0
};
\addplot3 [color=red,solid] table {
1 1 0
0.5 1 1
0 1 0
};
\addplot3 [color=red,solid] table {
1 0.5 0
1 1 1
0.5 1 0
};
% Plot function on the interior.
\addplot3
[
surf,
mesh/rows=10,
blue,
faceted color=black,
]
table[header=false] {3ddata.dat};
\end{axis}
\end{tikzpicture}
\end{document}
The resulting picture looks as follows:
Z buffer
can not combine different\addplot
commands and they are in the order of appearance.row sep=crcr
. Aside from that, it looks fine to me (in pgfplots 1.11 and 1.12). What is the outcome of the example shown in the question?row sep=crcr
, denoted\pgfplotsset{compat=newest}
in the preamble. In this case, the outcome of the MWE is as depicted in the answer. I just put the picture there.