-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplot.py
35 lines (32 loc) · 1.08 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
import matplotlib.pyplot as plt
import math
def plot(data, *labels, **params):
'''create a line plot of the concentration of a chemical specie
* data: pandas data frame, untidy format, time as the first column
* *label: name of the column to plot
* **params: parameters of the plot
* - log: [True, False]: logscaled y axis
'''
x = data["time"]
if params.get("log", False):
plot_function = plt.semilogy
else:
plot_function = plt.plot
for label in labels:
if label in data:
y = data[label]
plot_function(x, y, label=label)
plt.xlabel("time (hour)")
else:
print("WARNING: label {} not found in data".format(label))
plt.ylabel("concentration (M)")
plt.legend()
plt.show()
def fraction_plot(data, *labels, **params):
x = data["time"]
y = data[labels]
y_frac = y.divide(y.sum(axis=1), axis=0)
plt.stackplot(x, *[y_frac[label] for label in labels], labels=labels)
plt.xlabel("time (hour)")
plt.legend()
plt.show()