# Contour plots with PSTricks

I'd like to use the PSTricks functionality to get the contour plots of 3D surfaces (more precisely, corresponding to functions z = f(x,y) from R^2 to R). Since, to the best of my knowledge, there is no package including this functionality, I've resorted to using the pst-solides3d package in order to plot the surface with an appropriate range of colors encoding the z value and choosing the viewpoint with an azimuthal angle set to 90 (sexagesimal degrees). In some cases this works (I've obtained good results with some trigonometric functions). In others, the result is simply wrong: I've tried with a parabolloid z = x^2 + y^2 having the plot restricted to the first octant and (x,y) \leq (1,1), but the view I've obtained with the azimuthal angle set to 90 degrees is flawed. What follows is an MWE for the parabolloid:

\documentclass{memoir}

\usepackage[pdfcrop={--hires}]{auto-pst-pdf}
\usepackage{xcolor,pstricks,pst-solides3d}

\begin{document}
\pagestyle{empty}
\psset{unit=3cm}
\begin{pspicture}(-2,-2)(2,2)
\psset{lightsrc=viewpoint,
viewpoint=60 0 90 rtp2xyz,
Decran=60}
\psSurface[linewidth=0.01pt,
ngrid=0.01 0.01,
tablez=0 0.01 2 {} for,
zcolor=0.5 0,
grid](0,0)(1,1){x x mul y y mul add}
\end{pspicture}
\end{document}


Please observe how the boundary of the plot is not actually a square -- as it should from the viewpoint I've chosen -- because it curves near the corner corresponding to the point (1,1,0). This is wy I say that the plot is flawed''.

I know there are two Perl scripts available from http://tug.org/PSTricks/main.cgi?file=pst-plot/3D/contour that have been devised with the aim to providing the functionality I'm looking for, but both links to the scripts lead actually to the same script, namely, to MakeData.pl. Besides, there are no indications as to what to do with them. I'm using the MikTeX 2.9 distribution; are the scripts to be saved in the miktex/bin folder, where other scripts are saved? Could anyone possibly provide any further hints as to how to use these scripts?

On the other hand, anyone knows of a different approach to obtain contour plots with PSTricks-based techniques?

-
give a complete example that z = x^2 + y^2 didn't work. The perl script can be saved in any directory where it will be found. Alternetively the documents directory –  Herbert Jan 23 '13 at 13:45
@Herbert: I've included an MWE to illustrate the issue with the parabolloid. On the other hand, both links for the Perls scripts still lead to the same file. –  Marcos Jan 24 '13 at 17:13

the coordinates of the pspicture environment is in 2D. Looking from the z axis the lowest y value is -1 and the highest 0. And looking from the z-axis with a perpective view we do not see a real square in the x-y plane.

\documentclass{memoir}

\usepackage[pdfcrop={--hires}]{auto-pst-pdf}
\usepackage{pst-solides3d}

\begin{document}
\pagestyle{empty}
\psset{unit=3cm}
\psframebox{%
\begin{pspicture}(0,-1)(1,0)
\psset{lightsrc=viewpoint,viewpoint=60 0 90 rtp2xyz,Decran=60}
\psSurface[linewidth=0.01pt,
ngrid=0.01 0.01,
tablez=0 0.01 2 {} for,
zcolor=0.5 0,
grid,
algebraic](0,0)(1,1){x^2+y^2}
\end{pspicture}}
%
\psframebox{%
\begin{pspicture}(0,-1)(1,0)
\psset{lightsrc=viewpoint,viewpoint=60 10 80 rtp2xyz,Decran=60}
\psSurface[linewidth=0.01pt,
ngrid=0.01 0.01,
tablez=0 0.01 2 {} for,
zcolor=0.5 0,
grid,
algebraic](0,0)(1,1){x^2+y^2}
\end{pspicture}}
\end{document}


-
I guess the OP is surprised by the appearance of the left plot because they're not aware that the plot is shown using a perspective projection. –  Jake Jan 24 '13 at 21:29
@{Herbert,Jake}: I still think this is the wrong result. When viewed from the vertical top down the 3D surface must project onto the square [0,1]\times[0,1] since that's the original set. Further, I believe the 2D coordinates for the pspicture environment to be irrelevant in this regard since I'm using auto-pst-pdf and compiling via pdflatex -shell-escape. I think this leads to a properly cropped picture in its own pdf page for each pspicture environment disregarding the 2D coordinates. –  Marcos Jan 24 '13 at 21:37
@Marcos: Sure as I already said the 2D coordinates are not relevant and only for the view from the top you can guess the coordinates for pspicture. However, I do not understand your problem. Use \axesIIID(1,1,1) for the first example and you'll see that the origin is nearly the same for 2D and 3D –  Herbert Jan 24 '13 at 21:53
@Herbert: My point is that the parabolloid constrained to that region should project as a square, whereas what we have in the picture is not so since it curves outwards'' near the corner with coordinates (1,1,0). –  Marcos Jan 24 '13 at 22:54
@Marcos: We have a perspective view, it cannot be a square in 2d –  Herbert Jan 25 '13 at 6:41