I'd like to draw z=x^2+y^2 on the interval 0<z<9. So normally I've just been using pgfplots with the addplot3 command, and for rectangular domains that doesn't seem to cause too much trouble. Example (from Is there any easy way to draw a ruled surface like a hyperbolic paraboloid in TikZ?):

enter image description here

In my case, however, I'd like to draw a paraboloid and I'd like the edge of the curve to be at r=3 in the z=9 plane. My first attempt was something like this (adapted from previous question):

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xmin=-3,ymin=-3,zmin=0,xmax=3,ymax=3,zmax=10]
\addplot3 [surf,draw=none,restrict z to domain=0:9] {x^2+y^2};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

Clearly the domain causes a problem: the paraboloid doesn't print pretty at all because the last z value evaluated is not at z=9, it is rather somewhere close to that below z=9, varying for each pair of coordinates (x,y).

I could set samples y=300, but the compilation time will be insane. Also, it limits the possibilities of the document, since I'm consuming a lot of stack size.

enter image description here

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xmin=-3,ymin=-3,zmin=0,xmax=3,ymax=3,zmax=10]
\addplot3 [surf,draw=none,restrict z to domain=0:9,samples y=300] {x^2+y^2};
\end{axis}
\end{tikzpicture}
\end{document}

Surely there's a better way to do this?

  • You have to switch to polar description of the surface to make the level sets parallel to the xy plane. Then you can cut the surface in a sane fashion. Pgfplots don't know how to chop off the mesh in the middle to limit the visible region. – percusse Apr 21 '15 at 9:31
up vote 4 down vote accepted

As percusse said in the comment, you could use polar coordinates:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xmin=-3,ymin=-3,zmin=0,xmax=3,ymax=3,zmax=10]
\addplot3 [surf,draw=none,restrict z to domain=0:9, data cs=polar, domain=0:360, y domain=0:3] (x, y, y^2);
\end{axis}
\end{tikzpicture}
\end{document}

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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