Skip to content

Commit ed05671

Browse files
committed
Plots now export bin file for later visualization 📈
1 parent 57f1ed7 commit ed05671

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

tools/at_home_plot.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import os
1010
import sys
11+
import pickle as pl
1112
import pandas as pd
1213
import numpy as np
1314
import matplotlib.pyplot as plt
@@ -39,15 +40,18 @@
3940
at_home_data.append([sum(x) for x in zip(data['G9A'], data['G10A'], data['G11A'], data['G12A'])])
4041

4142
# Plot the at_home_data with low opacity
43+
fig = plt.figure(figsize=(18.5, 10.5))
44+
ax = fig.gca()
45+
4246
for data in at_home_data:
43-
plt.plot(np.linspace(0, len(data) * 15 // (24 * 60), len(data)), data, alpha=0.1)
47+
ax.plot(np.linspace(0, len(data) * 15 // (24 * 60), len(data)), data, alpha=0.1)
4448

4549
# Get the "average" at home plot
4650
avg_data = savgol_filter([np.nanmedian(data_at_y) for data_at_y in itertools.zip_longest(*at_home_data, fillvalue=0)], 89, 3)
47-
plt.plot(np.linspace(0, len(avg_data) * 15 // (24*60), len(avg_data)), avg_data)
51+
ax.plot(np.linspace(0, len(avg_data) * 15 // (24*60), len(avg_data)), avg_data)
4852

49-
plt.title("Number of people absent from school due to measles infection")
5053
plt.xlabel("Time (days)")
5154
plt.ylabel("# of people")
5255

53-
plt.show()
56+
# Pickle
57+
pl.dump(fig, open(sys.argv[2], 'wb+'))

tools/infected_visualization.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import sys
1111
import pandas as pd
1212
import numpy as np
13+
import pickle as pl
1314
import matplotlib.pyplot as plt
1415

1516
import itertools
@@ -45,9 +46,10 @@
4546
# Get the "average" at home plot
4647
avg_data = savgol_filter([np.nanmedian(data_at_y) for data_at_y in itertools.zip_longest(*infected_data, fillvalue=0)], 89, 3)
4748
plt.plot(np.linspace(0, len(avg_data) * 15 // (24*60), len(avg_data)), avg_data)
48-
49-
plt.title("Number of people infected with measles due to measles outbreak")
5049
plt.xlabel("Time (days)")
5150
plt.ylabel("# of people")
5251

53-
plt.show()
52+
fig = plt.gcf()
53+
54+
# Pickle
55+
pl.dump(fig, open(sys.argv[2], 'wb+'))

tools/plot_population.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import sys
1010
import itertools
1111
import pandas as pd
12+
import pickle as pl
1213
import numpy as np
1314
import matplotlib.pyplot as plt
1415

@@ -65,7 +66,7 @@
6566
vacc_rate = 100 * (by_grade_data[9]['V'][0][0] / (by_grade_data[9]['S'][0][0] + by_grade_data[9]['V'][0][0] + 1))
6667
a = 0.02 # Alpha
6768

68-
fig = plt.figure()
69+
fig = plt.figure(figsize=(20,10), dpi=100)
6970
grade9_ax = fig.add_subplot(221)
7071
grade10_ax = fig.add_subplot(222)
7172
grade11_ax = fig.add_subplot(223)
@@ -131,5 +132,7 @@
131132

132133
fig.suptitle(
133134
'Compartmentalization of students in different grades within a secondary school during a measles outbreak\n (Vaccination rate: ' + str(round(vacc_rate, 2)) + '%)')
134-
135-
plt.show()
135+
136+
137+
# Pickle
138+
pl.dump(fig, open(sys.argv[2], 'wb+'))

0 commit comments

Comments
 (0)