This post is triggered by a discussion how to plot a function usin Python Matplotlib (Innaya, 2022). It is assumed that following function of Rayleigh cross section $C_S$
$$\tag{1} C_s = \frac{8 \pi}{3} \left( \frac{\varepsilon_1 - \varepsilon_2}{\varepsilon_1 + 2 \varepsilon_2} \right)^2 k^4 a^6 $$
is to be plotted againts wavelength $\lambda$, with $k = 2\pi / \lambda$ is wavenumber. There is similar equation with different form (Wikipedia, 2022). Using Python dictionary (Sannikov, 2022) code to plot cross section for four different materials is as follow.
import math
import matplotlib.pyplot as plt
# air
eps2 = 1.0054
# list of materials
materials = {
"PE": 2.25,
"Paper": 2.1,
"PTFE": 2.4,
"PS": 4.7,
"Glass": 7,
"Rubber": 11.68,
"Silicon": 30,
"Methanol": 4.5
}
# sphere radius (in nm)
a = 40
# wavelength l is in nm
def wavenumber(l):
k = 2 * math.pi / (l * 1E-9)
return k
# Rayleigh cross section
def rayleigh_cross_section(l, a, eps1, eps2):
g = (eps1 - eps2) / ( eps1 + 2 * eps2)
k = wavenumber(l)
b = a * 1E-9
cs = (8 * math.pi / 3) * (g**2) * (k**4) * (b**6)
return cs
# wavelength
lmin = 300
lmax = 800
dl = 10
l = [i for i in range(lmin, lmax + dl, dl)]
# material 1
eps1 = materials["PS"]
c1 = []
for i in l:
cs = rayleigh_cross_section(i, a, eps1, eps2)
c1.append(cs)
# material 2
eps1 = materials["PE"]
c2 = []
for i in l:
cs = rayleigh_cross_section(i, a, eps1, eps2)
c2.append(cs)
# material 3
eps1 = materials["Silicon"]
c3 = []
for i in l:
cs = rayleigh_cross_section(i, a, eps1, eps2)
c3.append(cs)
# material 4
eps1 = materials["Rubber"]
c4 = []
for i in l:
cs = rayleigh_cross_section(i, a, eps1, eps2)
c4.append(cs)
# plot of all curves
plt.title('Materials')
plt.plot(l, c1, '-o', label='Polystyrene')
plt.plot(l, c2, '-^', label='Polyethylene')
plt.plot(l, c3, '-s', label='Silicon')
plt.plot(l, c4, '-D', label='Rubber')
plt.xlabel('lambda')
plt.ylabel('cross section')
plt.legend(loc="upper right")
plt.show()
The explanation, code, and result in a Jupyter Notebook example is available here.