# How to plot spherical harmonics? [closed]

Let me start by saying that I am only interested in the mathematical aspect of the thing.

I would like to plot just for the fun of it the spherical harmonics that are used to plot the electronic clouds of atoms.

I found this on Wikipedia:

I don't understand the notation they use or the reference system, what am I supposed to write?

I think it makes sense to use the spherical coordinate system: \left\{ \begin{aligned} x &= r\sin \theta \,\cos \varphi,\\ y &= r\sin \theta \,\sin \varphi,\\ z &= r\cos \theta . \end{aligned} \right.

Instead of $$r$$ I have to put $$P_{\ell}^m(\cos\theta)\cos(m\theta)$$ and $$P_{\ell}^{|m|}(\cos\theta)\sin(|m|\theta)$$?

Indeed, that seems to be how these images were generated (except you have $$\theta$$ where you should have $$\varphi$$ in the last line). It doesn’t say so in the caption or the metadata of this image, but the caption of the first image in that Wikipedia article, which looks very similar, says:
Visual representations of the first few real spherical harmonics. Blue portions represent regions where the function is positive, and yellow portions represent where it is negative. The distance of the surface from the origin indicates the absolute value of $$Y_{\ell}^{m}(\theta,\varphi)$$ in angular direction $$(\theta,\varphi)$$.
So you do have to use the real spherical harmonics as the value of $$r$$ on the surface.