Update SIR_model.py
Browse files- SIR_model.py +27 -10
SIR_model.py
CHANGED
|
@@ -189,16 +189,33 @@ def main(total_population, initial_infected, initial_recovered, beta, gamma, mod
|
|
| 189 |
plt.show()
|
| 190 |
|
| 191 |
|
| 192 |
-
#
|
| 193 |
-
fig2 = plt.
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
plt.
|
| 198 |
-
plt.
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
plt.show()
|
| 203 |
|
| 204 |
return [fig1, fig2]
|
|
|
|
| 189 |
plt.show()
|
| 190 |
|
| 191 |
|
| 192 |
+
# Create an animated line graph
|
| 193 |
+
fig2, ax = plt.subplots()
|
| 194 |
+
ax.plot(times, s, label='Susceptible', color='blue')
|
| 195 |
+
ax.plot(times, i, label='Infected', color='orange')
|
| 196 |
+
ax.plot(times, r, label='Recovered', color='green')
|
| 197 |
+
ax.xaxis.set_major_locator(plt.MaxNLocator(6))
|
| 198 |
+
ax.xaxis.set_major_formatter(plt.FuncFormatter(lambda x, p: '{:.1f}'.format(x)))
|
| 199 |
+
ax.set_xlabel('Time')
|
| 200 |
+
ax.set_ylabel('Population')
|
| 201 |
+
ax.set_title('Population over time')
|
| 202 |
+
ax.legend()
|
| 203 |
+
ax.grid(True)
|
| 204 |
+
|
| 205 |
+
def animate(i):
|
| 206 |
+
ax.clear()
|
| 207 |
+
ax.plot(times, s, label='Susceptible', color='blue')
|
| 208 |
+
ax.plot(times, i, label='Infected', color='orange')
|
| 209 |
+
ax.plot(times, r, label='Recovered', color='green')
|
| 210 |
+
ax.xaxis.set_major_locator(plt.MaxNLocator(6))
|
| 211 |
+
ax.xaxis.set_major_formatter(plt.FuncFormatter(lambda x, p: '{:.1f}'.format(x)))
|
| 212 |
+
ax.set_xlabel('Time')
|
| 213 |
+
ax.set_ylabel('Population')
|
| 214 |
+
ax.set_title('Population over time')
|
| 215 |
+
ax.legend()
|
| 216 |
+
ax.grid(True)
|
| 217 |
+
|
| 218 |
+
anim = FuncAnimation(fig2, animate, frames=times, interval=50, blit=True)
|
| 219 |
plt.show()
|
| 220 |
|
| 221 |
return [fig1, fig2]
|