#SIR Epidemic Model

import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt

# Total population, N.
N = 10000
# Initial number of people infected and recovered individuals, I0 (infected) and R0 (recovered).
I0, R0 = 100, 0
# Everyone else, S0, is susceptible to infection initially. Population - infected - recovered = susceptible
S0 = N - I0 - R0
# Contact rate, beta, and mean recovery rate, gamma, (in 1/days).
beta, gamma = 0.20, 1/14 
#Create grid of time points (in days)
t = np.linspace(0, 200, 200)

#SIR differential equations.
def deriv(y, t, N, beta, gamma):
    S, I, R = y
    dSdt = -beta * S * I / N
    dIdt = beta * S * I / N - gamma * I
    dRdt = gamma * I
    return dSdt, dIdt, dRdt

#Starting conditions vector
y0 = S0, I0, R0

#Pass in SIR equations over the time grid, t.
ret = odeint(deriv, y0, t, args=(N, beta, gamma))
S, I, R = ret.T

# Plot results data on three separate curves for S(t), I(t) and R(t)
fig = plt.figure(facecolor='w')
ax = fig.add_subplot(111, axisbelow=True)
ax.plot(t, S/1000, 'b', alpha=0.5, lw=2, label='Susceptible')
ax.plot(t, I/1000, 'r', alpha=0.5, lw=2, label='Infected')
ax.plot(t, R/1000, 'g', alpha=0.5, lw=2, label='Recovered with immunity')
ax.set_xlabel('Time / in days')
ax.set_ylabel('Number (1000s)')
ax.set_ylim(0,10.2) #set y axis limit on this line
ax.yaxis.set_tick_params(length=0)
ax.xaxis.set_tick_params(length=0)
ax.grid(b=True, which='major', c='w', lw=2, ls='-')
legend = ax.legend()
legend.get_frame().set_alpha(0.5)
for spine in ('top', 'right', 'bottom', 'left'):
    ax.spines[spine].set_visible(False)
plot.show()
display(fig)


#SIR Epidemic Model

import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt

# Total population, N.
N = 10000
# Initial number of people infected and recovered individuals, I0 (infected) and R0 (recovered).
I0, R0 = 100, 0
# Everyone else, S0, is susceptible to infection initially. Population - infected - recovered = susceptible
S0 = N - I0 - R0
# Contact rate, beta, and mean recovery rate, gamma, (in 1/days).
beta, gamma = 0.20, 1/14 
#Create grid of time points (in days)
t = np.linspace(0, 200, 200)

#SIR differential equations.
def deriv(y, t, N, beta, gamma):
    S, I, R = y
    dSdt = -beta * S * I / N
    dIdt = beta * S * I / N - gamma * I
    dRdt = gamma * I
    return dSdt, dIdt, dRdt

#Starting conditions vector
y0 = S0, I0, R0

#Pass in SIR equations over the time grid, t.
ret = odeint(deriv, y0, t, args=(N, beta, gamma))
S, I, R = ret.T

# Plot results data on three separate curves for S(t), I(t) and R(t)
fig = plt.figure(facecolor='w')
ax = fig.add_subplot(111, axisbelow=True)
ax.plot(t, S/1000, 'b', alpha=0.5, lw=2, label='Susceptible')
ax.plot(t, I/1000, 'r', alpha=0.5, lw=2, label='Infected')
ax.plot(t, R/1000, 'g', alpha=0.5, lw=2, label='Recovered with immunity')
ax.set_xlabel('Time / in days')
ax.set_ylabel('Number (1000s)')
ax.set_ylim(0,10.2) #set y axis limit on this line
ax.yaxis.set_tick_params(length=0)
ax.xaxis.set_tick_params(length=0)
ax.grid(b=True, which='major', c='w', lw=2, ls='-')
legend = ax.legend()
legend.get_frame().set_alpha(0.5)
for spine in ('top', 'right', 'bottom', 'left'):
    ax.spines[spine].set_visible(False)
plot.show()
display(fig)


#SIR Epidemic Model # Total population, N. # Initial number of people infected and recovered individuals, I0 (infected) and R0 (recovered). # Everyone else, S0, is susceptible to infection initially. Population - infected - recovered = susceptible # Contact rate, beta, and mean recovery rate, gamma, (in 1/days). #Create grid of time points (in days) #SIR differential equations. #Starting conditions vector #Pass in SIR equations over the time grid, t. # Plot results data on three separate curves for S(t), I(t) and R(t) #set y axis limit on this line