forked from mvdh7/python-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorial-3.py
More file actions
56 lines (47 loc) · 1.52 KB
/
tutorial-3.py
File metadata and controls
56 lines (47 loc) · 1.52 KB
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
import numpy as np, pandas as pd
# import matplotlib.pyplot as plt
from matplotlib import pyplot as plt
# Import titration file
file_to_use = "titration1"
data = np.genfromtxt('data/' + file_to_use + '.txt',
skip_header=2)
volume = data[:, 0]
emf = data[:, 1]
temperature = data[:, 2]
# combine the arrays into a dict
titration = {
"volume": volume,
"emf": emf,
"temperature": temperature,
}
titration = pd.DataFrame(titration)
# make a logical array
L = ((volume >= 3) & (emf < 460)) | (volume < 1)
# titration_L = {k: v[L] for k, v in titration.items()}
titration_L = titration[L]
# working with dataframes
vol = titration['volume'] # just like in a dict
vol = titration.volume # dot notation - doesn't work for everything
# ^ access columns
titration['whatever'] = 15
titration['volume_squared'] = titration.volume ** 2
# ^ assign new columns - can't use dot notation
vol_L = titration[L]['volume']
vol_L = titration['volume'][L]
vol_L = titration[L].volume
vol_L = titration.volume[L]
# ^ these are all the same thing: column and rows together
# Make a plot
fig, ax = plt.subplots(dpi=300)
# ax.scatter(volume, emf, s=35, c='xkcd:navy')
sc_full = ax.scatter('volume', 'emf', data=titration,
s=25, c='emf', cmap='plasma')
# ax.scatter(volume[L], emf[L], s=35, c='xkcd:tangerine',
# alpha=0.9)
sc = ax.scatter('volume', 'emf', data=titration[L],
s=25, c='emf')
plt.colorbar(sc)
plt.colorbar(sc_full)
ax.set_xlabel('Volume / ml')
ax.set_ylabel('EMF / mV')
ax.grid(alpha=0.3)