I am trying to draw a spherical harmonics for my college project. The following formula I want to depict,
Y = cos(theta)
for that, I wrote
The picture in the Wikipedia article Spherical harmonics is obtained by using the absolute value of a spherical harmonic as the r coordinate, and then coloring the surface according to the sign of the harmonic. Here is an approximation.
x, y, z = sph2cart(np.abs(Y), phi, tta)
fig = plt.figure()
ax = fig.add_subplot( 111 , projection='3d')
from matplotlib import cm
ax.set_aspect('equal')
ax.plot_surface(x, y, z, linewidth = 0.5, facecolors = cm.jet(Y), edgecolors = 'k')
When you use Y itself as r, the two hemispheres (positive Y and negative Y) end up mapped onto the same half of the above surface.