Skip to content

Commit 460b733

Browse files
committed
feat: made colors configurable for scatter plots
array based on healthy,infected, immune, dead
1 parent ff4faf0 commit 460b733

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed

plot.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,21 @@
33

44
mpl.style.use('style.mplstyle')
55

6+
# healthy, infected, immune, dead
7+
personStateColors = ['#404040', '#ff0000', '#00ff00', '#000000']
8+
9+
# sets graph title
610
def ax2Title(ax2):
711
ax2.set_title('number of infected')
812

13+
# updates figure with common values across all simulations
914
def figUpdate(ax1, ax2, x_plot, y_plot):
1015
ax1.set_xlim(x_plot[0], x_plot[1])
1116
ax1.set_ylim(y_plot[0], y_plot[1])
1217
ax1.axis('off')
1318
ax2Title(ax2)
1419

20+
# initialises figure with common values across all simulations
1521
def figInit(xbounds, ybounds, pop_size):
1622
fig = plt.figure(figsize=(5,7))
1723
spec = fig.add_gridspec(ncols=1, nrows=2, height_ratios=[5,2])

simple_simulation.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import matplotlib.pyplot as plt
66
from matplotlib.animation import FuncAnimation
77

8-
from plot import figInit, figUpdate
8+
from plot import figInit, figUpdate, personStateColors
99

1010
#set seed for reproducibility
1111
np.random.seed(100)
@@ -318,16 +318,16 @@ def update(frame, population, infection_range=0.01, infection_chance=0.03,
318318
figUpdate(ax1, ax2, xbounds, ybounds)
319319

320320
healthy = population[population[:,6] == 0][:,1:3]
321-
ax1.scatter(healthy[:,0], healthy[:,1], color='gray', s = 2, label='healthy')
321+
ax1.scatter(healthy[:,0], healthy[:,1], color=personStateColors[0], s = 2, label='healthy')
322322

323323
infected = population[population[:,6] == 1][:,1:3]
324-
ax1.scatter(infected[:,0], infected[:,1], color='red', s = 2, label='infected')
324+
ax1.scatter(infected[:,0], infected[:,1], color=personStateColors[1], s = 2, label='infected')
325325

326326
immune = population[population[:,6] == 2][:,1:3]
327-
ax1.scatter(immune[:,0], immune[:,1], color='green', s = 2, label='immune')
327+
ax1.scatter(immune[:,0], immune[:,1], color=personStateColors[2], s = 2, label='immune')
328328

329329
fatalities = population[population[:,6] == 3][:,1:3]
330-
ax1.scatter(fatalities[:,0], fatalities[:,1], color='black', s = 2, label='fatalities')
330+
ax1.scatter(fatalities[:,0], fatalities[:,1], color=personStateColors[3], s = 2, label='fatalities')
331331

332332
#add text descriptors
333333
ax1.text(xbounds[0],

simulation.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from population import initialize_population, initialize_destination_matrix,\
1313
set_destination_bounds, save_data
1414

15-
from plot import figInit, figUpdate
15+
from plot import figInit, figUpdate, personStateColors
1616

1717
#set seed for reproducibility
1818
np.random.seed(100)
@@ -118,16 +118,16 @@ def update(frame, population, destinations, pop_size, infection_range=0.01,
118118

119119
#plot population segments
120120
healthy = population[population[:,6] == 0][:,1:3]
121-
ax1.scatter(healthy[:,0], healthy[:,1], color='gray', s = 2, label='healthy')
121+
ax1.scatter(healthy[:,0], healthy[:,1], color=personStateColors[0], s = 2, label='healthy')
122122

123123
infected = population[population[:,6] == 1][:,1:3]
124-
ax1.scatter(infected[:,0], infected[:,1], color='red', s = 2, label='infected')
124+
ax1.scatter(infected[:,0], infected[:,1], color=personStateColors[1], s = 2, label='infected')
125125

126126
immune = population[population[:,6] == 2][:,1:3]
127-
ax1.scatter(immune[:,0], immune[:,1], color='green', s = 2, label='immune')
127+
ax1.scatter(immune[:,0], immune[:,1], color=personStateColors[2], s = 2, label='immune')
128128

129129
fatalities = population[population[:,6] == 3][:,1:3]
130-
ax1.scatter(fatalities[:,0], fatalities[:,1], color='black', s = 2, label='dead')
130+
ax1.scatter(fatalities[:,0], fatalities[:,1], color=personStateColors[3], s = 2, label='dead')
131131

132132

133133
#add text descriptors

simulation_hospital.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from population import initialize_population, initialize_destination_matrix,\
1313
set_destination_bounds, save_data
1414

15-
from plot import figInit, figUpdate
15+
from plot import figInit, figUpdate, personStateColors
1616

1717

1818
def update(frame, population, destinations, pop_size, infection_range=0.01,
@@ -97,21 +97,21 @@ def update(frame, population, destinations, pop_size, infection_range=0.01,
9797
healthy = population[population[:,6] == 0][:,1:3]
9898
ax1.scatter(healthy[:healthcare_workers][:,0],
9999
healthy[:healthcare_workers][:,1],
100-
marker= 'P', s = 2, color='green',
100+
marker= 'P', s = 2, color=personStateColors[2],
101101
label='healthy')
102102

103103
ax1.scatter(healthy[healthcare_workers:][:,0],
104104
healthy[healthcare_workers:][:,1],
105-
color='gray', s = 2, label='healthy')
105+
color=personStateColors[0], s = 2, label='healthy')
106106

107107
infected = population[population[:,6] == 1][:,1:3]
108-
ax1.scatter(infected[:,0], infected[:,1], color='red', s = 2, label='infected')
108+
ax1.scatter(infected[:,0], infected[:,1], color=personStateColors[1], s = 2, label='infected')
109109

110110
immune = population[population[:,6] == 2][:,1:3]
111-
ax1.scatter(immune[:,0], immune[:,1], color='green', s = 2, label='immune')
111+
ax1.scatter(immune[:,0], immune[:,1], color=personStateColors[2], s = 2, label='immune')
112112

113113
fatalities = population[population[:,6] == 3][:,1:3]
114-
ax1.scatter(fatalities[:,0], fatalities[:,1], color='black', s = 2, label='dead')
114+
ax1.scatter(fatalities[:,0], fatalities[:,1], color=personStateColors[3], s = 2, label='dead')
115115

116116

117117
#add text descriptors

0 commit comments

Comments
 (0)