-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathplot.py
74 lines (65 loc) · 1.47 KB
/
plot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# %%
import matplotlib.pyplot as plt
import numpy as np
import lovelyplots
# %%
def plot_dist(
temperatures,
v,
mass=85 * 1.66e-27,
pparam={"xlabel": "Speed", "ylabel": "Speed distribution"},
save_name="",
):
fig, ax = plt.subplots()
for T in temperatures:
fv = MB_speed(v, mass, T)
ax.plot(v, fv, label=f"T={T}K")
ax.legend()
ax.set(**pparam)
fig.savefig(save_name)
v = np.arange(0, 800, 10)
temperatures = [i for i in range(100, 500, 75)]
def MB_speed(v, m, T):
"""Maxwell-Boltzmann speed distribution for speeds"""
kB = 1.38e-23
return (
(m / (2 * np.pi * kB * T)) ** 1.5 * 4 * np.pi * v**2 * np.exp(-m * v**2 / (2 * kB * T))
)
styles = [
[
"ipynb",
"use_mathtext",
],
[
"ipynb",
"use_mathtext",
"colors5-light",
],
[
"ipynb",
"use_mathtext",
"colors10-ls",
],
[
"ipynb",
"use_mathtext",
"colors10-markers",
],
["classic"],
["ipynb"],
["paper", "use_mathtext"],
]
names = [
"out/ipynb+use_mathtext.svg",
"out/ipynb+use_mathtext+colors5-light.svg",
"out/ipynb+use_mathtext+colors10-ls.svg",
"out/ipynb+use_mathtext+colors10-markers.svg",
"out/classicmpl.svg",
"out/ipynb.svg",
"out/paper+use_mathtext.svg",
]
# %%
for style, name in zip(styles, names):
with plt.style.context(style):
plot_dist(temperatures, v, save_name=name)
# %%