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.
The Y you are passing to the function needs to be an absolute value to make it r, else z = cos(theta)^2 is always positive. If r is to be the radius then this what you should be doing.
x, y, z = sph2cart(np.abs(Y), phi, tta)