0

I use matlab2tikz to generate figures, see attached first figure (this is an example to illustrate the problem) where two surfaces intersect each other. The generated tikz figure is shown below and the problem is that tikz does not seem to distinguish between which surface is 'on top' viewed from the viewing angle, making it difficult to analyse the figures when the shape of the surfaces are more complex than what is shown. Is there a way of getting tikz to look more like the original matlab figure?

matlab code:

 x = [-1 1];
 y = [-1 1];
 
 z1 = [0 0; 0 0];
 z2 = [0 1; -1 0];
 
 
 figure
 surf(x,y,z1, 'facealpha', 0.5, 'facecolor', 'b'); 
 hold on; 
 surf(x,y,z2, 'facealpha', 0.5, 'facecolor', 'g')
 
 matlab2tikz;

tex code: (built w PDFLaTeX)


\documentclass{article}

  \usepackage{pgfplots}
  \pgfplotsset{compat=newest}
  \usetikzlibrary{plotmarks}
  \usetikzlibrary{arrows.meta}
  \usepackage{grffile}
  \usepgfplotslibrary{external}
  \usepackage{subcaption}


\begin{document}

\begin{tikzpicture}

\begin{axis}[%
width=3.557in,
height=3.566in,
at={(0.597in,0.481in)},
scale only axis,
xmin=-1,
xmax=1,
tick align=outside,
ymin=-1,
ymax=1,
zmin=-1,
zmax=1,
view={-37.5}{30},
axis background/.style={fill=white},
axis x line*=bottom,
axis y line*=left,
axis z line*=left,
xmajorgrids,
ymajorgrids,
zmajorgrids,
legend style={at={(1.03,1)}, anchor=north west, legend cell align=left, align=left, draw=white!15!black}
]

\addplot3[%
surf,
fill opacity=0.5, fill=blue, faceted color=black, z buffer=sort, mesh/rows=2]
table[row sep=crcr, point meta=\thisrow{c}] {%
%
x   y   z   c\\
-1  -1  0   0\\
-1  1   0   0\\
1   -1  0   0\\
1   1   0   0\\
};


\addplot3[%
surf,
fill opacity=0.5, fill=green, faceted color=black, z buffer=sort, mesh/rows=2]
table[row sep=crcr, point meta=\thisrow{c}] {%
%
x   y   z   c\\
-1  -1  0   0\\
-1  1   -1  -1\\
1   -1  1   1\\
1   1   0   0\\
};

\end{axis}

\end{tikzpicture}%

\end{document}



original figure

tikz figure

Your Answer

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

Browse other questions tagged or ask your own question.