7

I'm a newcomer to LaTeX and pgfplots. And now I found a problem while I was using \addplot3. It seems that the image behaved abnormally on perspective.This is the image generated. enter image description here

For reference I changed to view={20}{0}, and it became the image below. enter image description here

Could anyone tell me how to deal with it, please? I don't know how to make the first image right. My tex code is

%!TEX program = xelatex
\documentclass{article}
\usepackage{fontspec, xunicode, xltxtra, pgfplots}  
\setmainfont{Hiragino Sans GB}  
\pgfplotsset{compat=1.8}

\title{Title}
\author{}

\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}
    \begin{axis}[
title={$x \exp(-x^2-y^2)$},
xlabel=$x$, ylabel=$y$,
small,
view={20}{30}
] \addplot3[surf,mesh/cols=50,domain=-2:2,domain y=-1.3:1.3]
            table {2.dat};
    \end{axis}
\end{tikzpicture}
\caption{a small example}
\end{figure}

\end{document}

THANKS!

  • 3
    Welcome to the site. I say print 1000 copies and sell it as an "M.C. Escher" original print. Good first question! – Steven B. Segletes May 13 '16 at 19:06
  • 2
    Try putting z buffer=sort in your \addplot3 [...] options. – Jake May 13 '16 at 19:08
  • 1
    Did you try z buffer= sort? – Faekynn May 13 '16 at 19:08
  • 1
    Could you provide your data file? When plotting just the function {x*exp(-x*x-y*y)}, I could not reproduce the behavior... – Faekynn May 13 '16 at 20:24
  • 1
    Hi, am author of pgfplots. Could you provide the data file 2.dat? pgfplots is supposed to draw plots like that correctly out of the box and I will see what I can do. If the file is too long (looks like 50x50), you can send it by mail (my address is in on top of the pgfplots manual). – Christian Feuersänger May 14 '16 at 6:51
1

As suggested in the comments, use the option z buffer = sort to correct the sorting in the data file. If you plot the function directly in pgfplots, the problem does not exist....

\documentclass{article}
\usepackage{pgfplots}  
\pgfplotsset{compat=1.8}


\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}
    \begin{axis}[
title={$x \exp(-x^2-y^2)$},
xlabel=$x$, ylabel=$y$,
small,
view={20}{20}
] 
\addplot3[surf,domain=-2:2,domain y=-2:2,samples=50]
           {x*exp(-x*x-y*y)} ;
    \end{axis}
\end{tikzpicture}
\caption{a small example}
\end{figure}

\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.