Skip to content
Snippets Groups Projects
Commit 705e8066 authored by Timon Idema's avatar Timon Idema
Browse files

Fixed typo in Maxwell dist plot legend.

parent 5efd0bd1
No related branches found
No related tags found
No related merge requests found
......@@ -414,7 +414,7 @@ v = np.linspace(0, 6, 600)
# Actual plots.
line1 = ax.plot(v, f(v, 1), label='low $T$')
line2 = ax.plot(v, f(v, 3), label='hight $T$')
line2 = ax.plot(v, f(v, 3), label='high $T$')
# Lines to plot from v-axis.
ax.plot([v0(1), v0(1)], [0, f(v0(1), 1)], color='C0', linestyle = '--')
......
%% Cell type:markdown id: tags:
# Plot of the Maxwell distribution
For section 13.5.3
%% Cell type:markdown id: tags:
Maxwell distribution:
$$
f_\mathrm{Maxwell}(v) = \left( \frac{m}{2\pi k_\mathrm{B} T} \right)^{3/2} 4 \pi v^2 \exp\left(-\frac{m v^2}{2 k_\mathrm{B} T} \right)
$$
Average 'thermal speed' of each molecule
$$
v_\mathrm{th} = \sqrt{\frac{3 k_\mathrm{B} T}{m}}.
$$ (thermalspeed)
%% Cell type:code id: tags:
``` python
# Python libraries.
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
```
%% Cell type:code id: tags:
``` python
def f(v, T):
# Returns f(v), in units where kB = 1 and m = 1.
return np.power(1/(2*np.pi*T),1.5) * 4 * np.pi * v * v * np.exp(- 0.5 * v * v / T)
def v0(T):
# Returns v0(T), the maximum of the Maxwell distribution, in units where kB = 1 and m = 1.
return np.sqrt(2*T)
def vth(T):
# Returns v_{th}T, in units where kB = 1 and m = 1.
return np.sqrt(3*T)
```
%% Cell type:code id: tags:
``` python
fig, ax = plt.subplots(figsize=(6,4))
v = np.linspace(0, 6, 600)
line1 = ax.plot(v, f(v, 1), label='low $T$')
line2 = ax.plot(v, f(v, 3), label='hight $T$')
line2 = ax.plot(v, f(v, 3), label='high $T$')
# Lines to plot from v-axis.
ax.plot([v0(1), v0(1)], [0, f(v0(1), 1)], color='C0', linestyle = '--')
ax.plot([vth(1), vth(1)], [0, f(vth(1), 1)], color='C0', linestyle = ':')
ax.plot([v0(3), v0(3)], [0, f(v0(3), 3)], color='C1', linestyle = '--')
ax.plot([vth(3), vth(3)], [0, f(vth(3), 3)], color='C1', linestyle = ':')
# Below doesn't work as matplotlib interprets fractional values of ymax as fraction of total height.
#ax.axvline(x=v0(1), ymax=f(v0(1),1), color = 'k', linestyle = ':')
#ax.axvline(x=vth(1), ymax=f(vth(1), 1), color = 'k', linestyle = '--')
#ax.axvline(x=v0(3), ymax=f(v0(3), 3), color = 'k', linestyle = ':')
#ax.axvline(x=vth(3), ymax=f(vth(3), 3), color = 'k', linestyle = '--')
ax.set_xlim(0,6)
#ax.set_xticks([0, np.pi, 2*np.pi, 3*np.pi, 4*np.pi], labels=['$0$', '$\\pi$', '$2\\pi$', '$3\\pi$', '$4\\pi$'])
#ax.set_yticks([-1, -0.5, 0, 0.5, 1], labels=['$-1$', '$-\\frac{1}{2}$', '$0$', '$\\frac{1}{2}$', '$1$'])
ax.set_ylim(0,0.6)
ax.set_xlabel('$v$')
ax.set_ylabel('$f(v)$')
ax.text(v0(1), -0.01, r'$v_0$', color='C0', horizontalalignment='center', verticalalignment='top')
ax.text(vth(1), -0.01, r'$v_\mathrm{th}$', color='C0', horizontalalignment='center', verticalalignment='top')
ax.text(v0(3), -0.01, r'$v_0$', color='C1', horizontalalignment='center', verticalalignment='top')
ax.text(vth(3)+.18, -0.01, r'$v_\mathrm{th}$', color='C1', horizontalalignment='center', verticalalignment='top')
ax.legend()
#plt.savefig("dampedoscillations.pdf", format="pdf", bbox_inches="tight")
#plt.savefig("dampedoscillations.svg", format="svg", bbox_inches="tight")
```
%% Output
<matplotlib.legend.Legend at 0x12f52b680>
%% Cell type:code id: tags:
``` python
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment