Skip to content

Instantly share code, notes, and snippets.

@kumpeishiraishi
Last active May 30, 2017 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kumpeishiraishi/c39baecc07bf6f51670d1fefc8e54aa1 to your computer and use it in GitHub Desktop.
Save kumpeishiraishi/c39baecc07bf6f51670d1fefc8e54aa1 to your computer and use it in GitHub Desktop.
Draw spherical harmonics with your preferred quantum numbers
import numpy as np
from scipy.special import sph_harm
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# Designate quantum numbers here!
m = 1
l = 3
point_size = 100
theta = np.linspace(0,np.pi,num=point_size)
phi = np.linspace(0,2*np.pi,num=point_size)
r = 2
x = r*np.outer(np.sin(theta),np.cos(phi))
y = r*np.outer(np.sin(theta),np.sin(phi))
z = r*np.outer(np.cos(theta),np.ones(point_size))
T = np.outer(theta,np.ones(point_size))
P = np.outer(np.ones(point_size),phi)
R = np.abs(np.real(sph_harm(m,l,P,T)))
fig = plt.figure()
ax = fig.add_subplot(111,projection="3d")
ax.plot_wireframe(R*x,R*y,R*z)
plt.savefig("20170530_sph_harm_3_1.png",dpi=300)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment