Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm struggling with a 3D representation through the use of the package pgfplots. I'm faced with an alleged error in pgfplots (from my point of view). Consider the txt file (which is attached here) and the following code that uses it:

\documentclass[a4paper,11pt]{memoir}

\usepackage{pgfplots}
\pgfplotsset{/pgf/number format/use comma}

\begin{document}
\begin{tikzpicture}
\begin{axis} [view={45}{35},
    xlabel=$\sigma_2$,
    ylabel=$\sigma_1$,
    zlabel={$\phi$},
    %zmin=-6E-5,
    %zmax=0,
    grid=major,
    colormap/blackwhite,
    title={Grafico}]

\addplot3 [surf,z buffer=sort] file {grafico.txt};
\end{axis}
\end{tikzpicture}

\end{document}

Try to compile it as I wrote and look at the surface. Now try to uncomment the lines zmin =-6E-5 and zmax = 0, and recompile. As you can see the clip of the surface is made ​​with respect to the outermost edge of the chart and not with respect to the plane z = 0, as it should be.

I also tried with the analytical formulation:

\documentclass[a4paper,11pt]{memoir}

\usepackage{pgfplots}
\pgfplotsset{/pgf/number format/use comma,compat=1.8}

\begin{document}
\begin{tikzpicture}
\begin{axis} [view={25}{35},
    xlabel=$\sigma_1$,
    ylabel=$\sigma_2$,
    zlabel={$\varphi$},
%   xmin=-.0025,
%   xmax=.0025,
%   ymin=-.01,
%   ymax=.01,
    zmin=-6E-5,
    zmax=0,
    grid=major,
    colormap/blackwhite,
    title={Grafico}]

\addplot3 [surf, shader=interp, z buffer=sort, samples=15, domain=-.0025:.0025, y domain=-.01:.01] {y^2-.9^2*(x-2.8E-3)^2+2*4.032E-3*(x-2.8E-3)};

\end{axis}
\end{tikzpicture}

\end{document}

But also this does not work. Do you know how to correct this error? Or, can you tell me where I'm wrong?

share|improve this question
2  
You are right pgfplots just clips the 2d image - its 3d features are not fully developed. –  Andrew Swann Jun 5 '13 at 10:24
1  
Welcome to TeX.SX! You can have a look on our starter guide to familiarize yourself further with our format. :) Note that you don't have to sign with your name since it automatically appears in the lower right corner of your post. –  Claudio Fiandrino Jun 5 '13 at 10:31
    
Thanks for the comment, @Andrew. I hope that one day even the 3D features will be fully developed. –  Marco87 Jun 5 '13 at 11:14
    
Thanks @ClaudioFiandrino! I will follow the directions you gave me. –  Marco87 Jun 5 '13 at 11:15

1 Answer 1

You could either set the too high/too low values to the upper/lower boundary via max()/min() constructions (which might be undesirable), or you can use the z filter key. As with both the plot becomes more "unsmooth", I used samples=50, which makes things a lot slower, so probably you should use the external library of TikZ.

Code

\documentclass[tikz,border=2mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{/pgf/number format/use comma,compat=1.8}

\begin{document}

\begin{tikzpicture}
\begin{axis}
[   view={25}{35},
  xlabel=$\sigma_1$,
  ylabel=$\sigma_2$,
  zlabel={$\varphi$},
  grid=major,
  %colormap/blackwhite,
  title={Grafico},
  unbounded coords=jump,
]
\addplot3 [surf, shader=interp, z buffer=sort, samples=50, domain=-.0025:.0025, y domain=-.01:.01] {min(max(y^2-.9^2*(x-2.8E-3)^2+2*4.032E-3*(x-2.8E-3),-6E-5),0)};
\end{axis}
\end{tikzpicture}

\begin{tikzpicture}
\begin{axis}
[   view={25}{35},
  xlabel=$\sigma_1$,
  ylabel=$\sigma_2$,
  zlabel={$\varphi$},
  grid=major,
  %colormap/blackwhite,
  title={Grafico},
  z filter/.code={\pgfmathparse{or(#1>0,#1<-0.00006) ? nan : #1}},
  unbounded coords=jump,
  %unbounded coords=discard, % looks worse than jump
]
\addplot3 [surf, shader=interp, z buffer=sort, samples=50, domain=-.0025:.0025, y domain=-.01:.01] {y^2-.9^2*(x-2.8E-3)^2+2*4.032E-3*(x-2.8E-3)};
\end{axis}
\end{tikzpicture}

\end{document}

Output

enter image description here


Edit 1: As Jake pointed out, I reinvented the wheel and did manually what you can do with the keys restrict z to domain*=-6E-5 and restrict z to domain=-6E-5, where the former will yield the left output, while the latter will yield the right.

share|improve this answer
    
@Jake: D'oh! That key sounded oddly familiar, and checking old documents I found that I already used it in the past, but forgot about it. I'll update my post in a few minutes. –  Tom Bombadil Jun 9 '13 at 14:53
    
Thanks for the reply. Your code works (I have not figured out how to use the key restrict z to domain * =-6E-5 is the key restrict z to domain =-6E-5). Unfortunately, however, I find that the graphics quality is still not satisfactory. Fortunately in my document there will be one or two of 3D graphics similar to this. Therefore I believe that I could use the first solution that you suggested, perhaps by drawing a line with the curve of intersection between the surface and the plane is z = 0. I hope that this problem will soon be solved by the authors of the excellent package TikZ. –  Marco87 Jun 10 '13 at 11:05
    
Iy you can describe the points of your funtion as (x-Expression, y-Expression, z-Expression), you can improve the appearance like seen here –  Tom Bombadil Jun 10 '13 at 11:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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