I have a function $\psi(r,\theta,\phi=\phi_0)$ with $\phi_0\in \Re$, $r\in[0,R]$ with $R\in \Re$, and $\theta \in [0,\pi]$ (spherical polar coordinates) and I want to plot it in Mathematica. I guess the proper way to do that is in polar coordinates, but how do I do that?

The function is:

$$\psi(r,\theta,\phi=0)=r^2e^{-r}\cos \theta $$

  • $\begingroup$ Have you tried searching the docs? Lookup PolarPlot... $\endgroup$
    – rm -rf
    Commented Oct 25, 2013 at 15:40
  • 2
    $\begingroup$ How about ParametricPlot3D[{r Cos[θ], r Sin[θ], r^2 Exp[-r] Cos[θ]}, {r,0,4}, {θ,0,π}]. $\endgroup$
    – Greg Hurst
    Commented Oct 25, 2013 at 16:29
  • $\begingroup$ @rm-rf Yeah, but PolarPlot needs $r$ as function of $\theta$. $\endgroup$
    – Ana S. H.
    Commented Oct 25, 2013 at 16:38
  • $\begingroup$ What coordinate is supposed to represent $\psi$? $\endgroup$
    – Michael E2
    Commented Oct 25, 2013 at 19:46
  • $\begingroup$ @MichaelE2 Actually $\psi$ is a wave function for the Hydrogen Atom. $\endgroup$
    – Ana S. H.
    Commented Oct 27, 2013 at 3:21

2 Answers 2


First find the condition for $\phi=0$ in cartesian coordinates.

Last@CoordinateTransform["Cartesian" -> "Spherical", {x, y, z}];
Solve[% == 0, y]

{{y -> 0}}

Convert the expression to cartesian coordinates, apply the condition, and plot.

TransformedField["Spherical" -> "Cartesian", 
r^2 Exp[-r] Cos[θ], {r, θ, ϕ} -> {x, y, z}] /. %;

Plot3D[%, {x, -5, 5}, {z, -5, 5}, AxesLabel -> {x, z, ψ}]

enter image description here

Hope this is what you were looking for.

  • $\begingroup$ First you set y -> 0, which I agree with. But I do have a criticism/question: Next in Plot3D you plot the transformed expression (let expr = %) as if it were the graph of y == expr. Why y == expr if y is 0? $\endgroup$
    – Michael E2
    Commented Oct 26, 2013 at 1:06
  • $\begingroup$ Michael E2, Hopefully this fig en.wikipedia.org/wiki/File:3D_Spherical.svg will clear things. $\phi==0$ corresponds to $y==0$. $expr$ is a function of $x$ and $z$, and its values are plotted along the $y$ axis. $\endgroup$ Commented Oct 27, 2013 at 0:12
  • 1
    $\begingroup$ I know all that. That means the $y$ on the $y$ axis is not the same $y$ that is zero when $\phi=0$. That's confusing to me. I think $\psi$ ought to be treated as an intensity (as in DensityPlot) or as you have done (but not labeled $y$). $\endgroup$
    – Michael E2
    Commented Oct 27, 2013 at 0:26
  • $\begingroup$ I think you are taking issue with just the label? My thought flow is that there is one $y$ axis, the abscissae lie on $y==0$ and the ordinate can take values along the $y$ axis; and I also labeled it $y$. Now, I have changed it to $\psi$. $\endgroup$ Commented Oct 27, 2013 at 0:56
  • $\begingroup$ Yes, I had read it that the $y$'s were the same. With relabeling the confusion disappears. I don't think the OP's question is sufficiently clear yet, but this is a reasonable interpretation. +1. $\endgroup$
    – Michael E2
    Commented Oct 27, 2013 at 1:09

You could visualize with ColorFunction, e.g.:

f[x_, y_, z_] := Exp[-{x, y, z}.{x, y, z}] {x, y, z}.{x, y, z} z
min = NMinimize[f[x, 0, z], {x, z}][[1]];
max = NMaximize[f[x, 0, z], {x, z}][[1]];
cf = Function[{x, y, z}, 
   ColorData["Rainbow"][Rescale[f[x, 0, z], {min, max}]]];
Legended[ParametricPlot3D[{r Sin[t], 0, r Cos[t]}, {r, 0, 5}, {t, 0, 
   2 Pi}, ColorFunction -> cf, ColorFunctionScaling -> False, 
  Mesh -> False, PlotPoints -> 50], 
 BarLegend[{"Rainbow", {min, max}}]]

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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