[Tex/LaTex] How to draw a “Mexican hat potential” using 3dplot

3dtikz-pgf

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…

\tdplotsetmaincoords{70}{135}
\tdplotsetpolarplotrange{90}{180}{0}{360}
\begin{tikzpicture}[line join=bevel,tdplot_main_coords, fill opacity=.7]
\tdplotsphericalsurfaceplot[parametricfill]{72}{36}%
{4}{black}{\tdplottheta}%
{\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$};}%
\end{tikzpicture}

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:

\pgfplotsset{
   standard/.style={
    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}
}
}

\begin{tikzpicture}
 \begin{axis}[
 standard,
        colormap={blackwhite}{gray(0cm)=(1); gray(1cm)=(0)},
        samples=30,
        domain=0:360,
        y domain=0:1.25,
        zmin=0,
        zmax=2,
        xlabel=$\mathcal{RE}\,(\phi)$,
        ylabel=$\mathcal{IM}\,(\phi)$,
        zlabel=$V$,
        yticklabels={,,},
        xticklabels={,,},
        zticklabels={,,}
    ]
     \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);
    \end{axis}
\end{tikzpicture}

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!

Best Answer

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

enter image description here

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
            hide axis,
            samples=30,
            domain=0:360,
            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});
        \end{axis}
    \end{tikzpicture}
\end{document}