-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathhomework-4.py
39 lines (30 loc) · 1006 Bytes
/
homework-4.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
import pandas as pd, numpy as np
from matplotlib import pyplot as plt
from scipy import interpolate
# Import dataset
cal = pd.read_csv("cal.csv")
#%% Loop through variables
for element in cal.element.unique():
L = cal.element == element
# Interpolate the data
interp_linear = interpolate.interp1d(cal[L].concentration, cal[L].counts)
concentration_interp = np.linspace(np.min(cal[L].concentration), np.max(cal[L].concentration))
counts_linear = interp_linear(concentration_interp)
fig, axi = plt.subplots(dpi=300, figsize=(4, 6))
cal[L].plot.scatter(
"concentration",
"counts",
label=element,
ax=axi,
)
# Draw interpolation line
cal[L].plot(
concentration_interp, counts_linear, label="Interpolation", ax=axi
)
axi.legend()
# Settings and save
axi.grid(alpha=0.3)
axi.set_title(element)
plt.tight_layout()
plt.savefig("figures/homework/" + element + ".png")
plt.show()