8

I know there are some other mexican hat questions here, but none of the answers seems complete to me. I would like to draw the following figure with TikZ with similar axis and labeling. How can one do that?

My minimal example goes like

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\begin{document}
      \begin{tikzpicture}
        \begin{axis}[  axis lines=center, axis on top = false, 
    view={140}{15},axis equal,title={The Mexican hat potential},
          colormap={blackwhite}{gray(0cm)=(1); gray(1cm)=(0)},
            samples=30,
            domain=0:360,
            y domain=0:1.25,
            zmin=0,
        zmax=0.9,
        xlabel=$\phi_{Im}$,
        ylabel=$\phi_{Re}$,
        zlabel=$V$,
        yticklabels={,,},
        xticklabels={,,},
        zticklabels={,,}
        ]
        \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}

The output of which (see below) I don't like because I want a right handed coordinate system with z-axis pointing up and the x-axis pointing out of the screen as in the attached figure. If the dashes are too hard to implement I can do without them also.

In order to get the axes right, I have adjusted the view angle so as to "get it right", but this is also not straightforward at the moment. Finally, the labeling is definitely wrong as can be seen in the output. Any help would be appreciated.

EDIT: There seems to be some kind of bug with the labeling. I will try what's recommended in this thread.

Failed Mexican hat plot, failed labeling

enter image description here

5
  • So in principle you want the output from tex.stackexchange.com/questions/95247/… with axes?
    – Jake
    Feb 20, 2015 at 10:01
  • With similar axis as in my figure above and with the axis dashed up to some point. If possible Feb 20, 2015 at 10:05
  • I tried the OP's solution in your link, its horrible. The dude that answered that question had a good solution but forgot all about the axis and labeling. Probably took it for granted that everyone know this on top of their head. Feb 20, 2015 at 10:06
  • 7
    That dude is me. The question originally asked for this image to be reproduced, which doesn't include axes. The follow-up question on getting the axes was edited in two days after my answer was posted, I must have missed it (which is why one should leave a comment on the answer when posting a follow-up question).
    – Jake
    Feb 20, 2015 at 10:16
  • LOL Oops. OK but you had a good solution. Is it hard to add the axis? I have tried and played around with the code but all I get is a box for axis instead of the ones in the attached figure. Feb 20, 2015 at 10:19

2 Answers 2

8

Is it OK if we draw them?

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots,amsmath}
\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
            hide axis,
            %axis lines=middle,
%            axis on top,
%            axis line style={blue,dashed,thick},
%            ymin=-2,ymax=2,
%            xmin=-2,xmax=2,
%            zmin=-2,zmax=2,
            samples=30,
            domain=0:360,
            y domain=0:1.25,clip=false
        ]
        \addplot3 [surf, shader=flat, draw=black, fill=white, z buffer=sort]
           ({sin(x)*y}, {cos(x)*y}, {(y^2-1)^2});
        \draw[blue,thick,dashed] (axis cs:0,0,0) -- (axis cs:1,0,0)
                    node[below,font=\footnotesize]{$\phi_{\text{IM}}$};
        \draw[blue,thick,-stealth] (axis cs:1,0,0) -- (axis cs:1.3,0,0)
                    node[above,font=\footnotesize]{$\hat{y}$};
        \draw[blue,thick,dashed] (axis cs:0,0,0) -- (axis cs:0,-1,0)
                    node[left=2mm,font=\footnotesize]{$\phi_{\text{RE}}$};
        \draw[blue,thick,-stealth] (axis cs:0,-1,0) -- (axis cs:0,-1.5,0)
                    node[right=1mm,font=\footnotesize]{$\hat{x}$};
        \draw[blue,thick,dashed] (axis cs:0,0,0) -- (axis cs:0,0,1)
                    %node[left=2mm,font=\footnotesize]{$\phi_{\text{RE}}$}
                    ;
        \draw[blue,thick,-stealth] (axis cs:0,0,1) -- (axis cs:0,0,1.3)
                    node[right,font=\footnotesize]{$\hat{z}$};
        \end{axis}
    \end{tikzpicture}
\end{document}

enter image description here

2
  • 1
    You actually manage to reproduce what I asked for to a very good degree. So I accept your solution, but please have a look at mine too, it took me all day to make it :) Feb 20, 2015 at 14:23
  • 2
    @LoveLearning Good work. :-)
    – user11232
    Feb 20, 2015 at 23:19
4

Attention: I noticed that the below PDF of the Mexican Hat Potential is kind of corrupt. I suspect the shaded ball. It is corrupt in the sense that when you try to print it: On some softwares it cannot be printed (like acroread of UNIX) and with some other softwares only one quarter (the third quadrant) of the ball is actually printed together with the rest of the document.

Just for future users and for reference I would like to post my solution to this problem. Although it does not replicate the figure of the OP, it is kind of even better. So here's my code which is extremely manual in the sense that I had to get it by trial and error and by copy pasting from lots of different sources:

    \documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\usepackage{tikz}
\pgfdeclarefunctionalshading{sphere}{\pgfpoint{-25bp}{-25bp}}{\pgfpoint{25bp}{25bp}}{}{
%% calculate unit coordinates
25 div exch
25 div exch
%% copy stack
2 copy 
%% compute -z^2 of the current position 
dup mul exch
dup mul add
1.0 sub
%% and the -z^2 of the light source 
0.3 dup mul
-0.5 dup mul add
1.0 sub
%% now their sqrt product
mul abs sqrt
%% and the sum product of the rest
exch 0.3 mul add
exch -0.5 mul add
%% max(dotprod,0)
dup abs add 2.0 div 
%% matte-ify
0.6 mul 0.4 add
%% currently there is just one number in the stack.
%% we need three corresponding to the RGB values
dup
0.4
}
\begin{document}
      \begin{tikzpicture}
          \begin{axis}[  axis lines=center, axis on top = false, 
    view={140}{25},axis equal,title={The Mexican hat potential},
          colormap={blackwhite}{gray(0cm)=(1); gray(1cm)=(0)},
            samples=50,
            domain=0:360,
            y domain=0:1.25,
            zmin=0,
        xmax=1.5,
        ymax=1.5,
        zmax=1.5,
        x label style={at={(axis description cs:0.10,0.25)},anchor=north},
        y label style={at={(axis description cs:0.9,0.2)},anchor=north},
        z label style={at={(axis description cs:0.5,0.9)},anchor=north},
        xlabel = $\mathrm{Re}(\phi)$,
        ylabel=$\mathrm{Im}(\phi)$,
        zlabel=$V(\phi)$,
        yticklabels={,,},
        xticklabels={,,},
        zticklabels={,,}
        ]
        \addplot3 [surf, shader=flat, draw=black, fill=white, z buffer=sort] ({sin(x)*y}, {cos(x)*y}, {(y^2-1)^2});
        \end{axis}
        \shade[shading=sphere] (3.47,3.5) circle [radius=0.15cm];
        \shade[shading=sphere] (5.2,2.2) circle [radius=0.15cm]; 
        \node[anchor=east] at (4.05,3.71) (text) {A};
  \node[anchor=west] at (5.5,3.0) (description) {B};
  \draw (description) edge[out=180,in=0,<-] (text);
    \end{tikzpicture}
\end{document}

And here's the output of that: enter image description here

3
  • Is this Postscript syntax? Would you mind sharing some resources to learn that syntax? Mar 9, 2015 at 9:17
  • Hi, I have no idea what it is. I just copied a bunch of codes and remade them to look like this. (I'm not sure what a syntax is). In any case please have a look at this: tex.stackexchange.com/q/231706/39323 There seems to be some corruption in the code which can render the figure unprintable. Regards. Mar 9, 2015 at 9:43
  • @HenriMenke Postscript is a stack based language, so I recommend looking for resources for one of {Factor, Forth, PostScript}. It is a fun way to program, but it is not only a different syntax but the semantics are also kinda weird (i.e. you mostly manipulate the stack)
    – oerpli
    Apr 12, 2019 at 8:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .