Visualizing spherical harmonics in Python

不羁的心 提交于 2019-12-01 05:53:37

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)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!