# Drawing spherical harmonics with pst-3dplot

For my lecture notes in theoretical physics (namely quantum mechanics) I'm trying to visualize the spherical harmonics. I got Mathematica to plot them an this is what I did:

SphericalPlot3D[(Sqrt[3/(4*Pi)]*Sin[theta]*Cos[phi])^2,
{theta, 0, Pi}, {phi, 0, 2*Pi}, PlotRange -> All, PlotPoints -> 50]


That gives me this picture:

Now I want to plot it using pst-3dplot (or pst-solides3d) but I don't know how since there is no option like SphericalPlot3D. I tried using \parametricplotThreeD but this doesn't output anything useful. Here is my MWE for this

\documentclass{minimal}
\usepackage{pst-3dplot}
\begin{document}

\centering
\psset{algebraic=true}
\begin{pspicture}(-2,-3.5)(4,0)
\parametricplotThreeD[SphericalCoor=true](0,\psPi)(0,\psPiTwo)%
{t | u | (sqrt(3/(4*\psPi))*sin(t)*cos(u))^2}
\end{pspicture}

\end{document}


This is the output

-

The function \parametricplotThreeD takes the x,y,z-coordinates of the surface as arguments, whereas t and u are polar and azimuthal angles. The following code gives what you are looking for:

\documentclass{minimal}
\usepackage{pst-3dplot}
\begin{document}

\centering
\psset{algebraic=true}
\begin{pspicture}(-2,-3.5)(4,0)
\parametricplotThreeD[SphericalCoor=true](0,\psPi)(0,\psPiTwo)%
{ cos(u)^3*sin(t)^3 | sin(u)*sin(t)^3*cos(u)^2 | cos(t)*sin(t)^2*cos(u)^2 }
\end{pspicture}

\end{document}


Another option for nice 3D plots is Asymptote, see the gallery which also has a plot of a spherical harmonic.

-

Thanks to Alex' answer I was able to redo the plot using pst-solides3d

\documentclass[pstricks,border=3pt]{standalone}
\usepackage{pst-plot}
\usepackage{pst-solides3d}
\begin{document}

\begin{pspicture}(-1,-1)(1,1)
\defFunction[algebraic]{harmonic}(u,v)
{sin(u)*cos(v)*(sqrt(3/(4*\psPi))*sin(u)*cos(v))^2}
{sin(u)*sin(v)*(sqrt(3/(4*\psPi))*sin(u)*cos(v))^2}
{cos(u)*(sqrt(3/(4*\psPi))*sin(u)*cos(v))^2}
\psSolid[object=surfaceparametree,
base=0 pi 0 pi 2 mul,
function=harmonic,
linewidth=0.5\pslinewidth,
ngrid=25 40
]
\end{pspicture}

\end{document}


-

The required plot of this function can also be done with pgfplots in a short way with nice output.

I previously posted it on TikZ.de. It requires the recently released pgfplots 1.11, because I used a new feature to globally switch from degree to radian, because here radian is used.

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{colormaps}
\begin{document}
\begin{tikzpicture}
\begin{axis}[colormap/violet, hide axis]
surf,
domain     = 0:pi,
domain y   = 0:2*pi,
samples    = 50,
samples y  = 70,
z buffer   = sort
]
( {sin(x)*cos(y)*(sqrt(3/(4*pi))*sin(x)*cos(y))^2},
{sin(x)*sin(y)*(sqrt(3/(4*pi))*sin(x)*cos(y))^2},
{cos(x)*(sqrt(3/(4*pi))*sin(x)*cos(y))^2} );
\end{axis}
\end{tikzpicture}
\end{document}


-