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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to make a Mexican hat potential (like this one from Wikipedia)

enter image description here

drawing through TikZ, and I am sure the function to use is straightforward, but I have not managed to find the right solution myself... !

I am using this as a starting point, just need the right function...

\begin{tikzpicture}[line join=bevel,tdplot_main_coords, fill opacity=.7]
{\draw[color=black,thick,->] (0,0,0) -- (20,0,0) node[anchor=north east]{$x$};}%
{\draw[color=black,thick,->] (0,0,0) -- (0,20,0) node[anchor=north west]{$y$};}%
{\draw[color=black,thick,->] (0,0,0) -- (0,0,3) node[anchor=south]{$z$};}%

Any hints will be gratefully appreciated!!

Thanks again!

I now have a little problem getting the axis right. I want them placed in the middle of the plot, but I cannot seem to get the labels correct? Also, I would like to rotate the axis so that the x,y arrows point towards us, and the z up as it is now. Any tips? This is what I have now:

    axis x line=middle,
    axis y line=middle,
    axis z line=middle,
    enlarge x limits=0.15,
    enlarge y limits=0.15,
    enlarge x limits=0.15,
    every axis x label/.style={at={(current axis.right of origin)},anchor=north west},
    every axis y label/.style={at={(current axis.above origin)},anchor=north east},
    every axis z label/.style={at={(current axis.above origin)},anchor=south}

        colormap={blackwhite}{gray(0cm)=(1); gray(1cm)=(0)},
        y domain=0:1.25,
     \addplot3 [surf, shader=flat, draw=black,  z buffer=sort] ({sin(x)*y}, {cos(x)*y}, {(y^2-1)^2});
      %\addplot3 [surf, shader=flat, draw=black, fill=white, z buffer=sort] (x^4-x^2, y^4-y^2, 1);

It produces the following figure:

enter image description here

But as you see the axis labelling is not optimal, and the axis is rotated the wrong direction..

Thanks so much so far!

share|improve this question
Related: Mexican hat in TikZ. – Peter Grill Jan 24 '13 at 20:48

PGFPlots can plot 3D parametric functions. Here's the output using the function that is used for the Wikipedia image:

enter image description here

            hide axis,
            y domain=0:1.25
        \addplot3 [surf, shader=flat, draw=black, fill=white, z buffer=sort] ({sin(x)*y}, {cos(x)*y}, {(y^2-1)^2});
share|improve this answer
This is very nice. – Pouya Jan 24 '13 at 20:49
+1. How could I not discovered this before? – Sigur Jan 24 '13 at 20:52
Awesome, Jake! :) Soundtrack while running this example. :) – Paulo Cereda Jan 24 '13 at 20:57
Thanks a lot! I will try to modify this to my liking instead of using 3dplot, then, and use pgfplots. – user24949 Jan 24 '13 at 21:07
@user24949: Glad that it helps! If you consider this question answered, you can mark it as such by clicking the tick mark next to my answer. – Jake Jan 24 '13 at 22:26

Your Answer


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.