current (active) infections plot added in basics.py
This commit is contained in:
20
basics.py
20
basics.py
@@ -2,13 +2,15 @@
|
|||||||
Plot total cases of countries over time on log scale
|
Plot total cases of countries over time on log scale
|
||||||
"""
|
"""
|
||||||
import matplotlib.pyplot as pp
|
import matplotlib.pyplot as pp
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
def plot(data, countries):
|
def plot(data, countries):
|
||||||
figsize = (10,5)
|
figsize = (10,5)
|
||||||
tcp, tc = pp.subplots(figsize=figsize)
|
tcp, tc = pp.subplots(figsize=figsize) # total cases
|
||||||
tdp, td = pp.subplots(figsize=figsize)
|
tdp, td = pp.subplots(figsize=figsize) # total deaths
|
||||||
ncp, nc = pp.subplots(figsize=figsize)
|
tip, ti = pp.subplots(figsize=figsize) # total (currently) infected
|
||||||
ndp, nd = pp.subplots(figsize=figsize)
|
ncp, nc = pp.subplots(figsize=figsize) # new cases
|
||||||
|
ndp, nd = pp.subplots(figsize=figsize) # new deaths
|
||||||
for loc in data:
|
for loc in data:
|
||||||
if loc not in countries:
|
if loc not in countries:
|
||||||
continue
|
continue
|
||||||
@@ -26,12 +28,20 @@ def plot(data, countries):
|
|||||||
# new deaths
|
# new deaths
|
||||||
nd.plot(time, new_deaths, label=f"{loc}", marker=".")
|
nd.plot(time, new_deaths, label=f"{loc}", marker=".")
|
||||||
|
|
||||||
for ax, fig, name in [(tc, tcp, "total_cases"), (td, tdp, "total_deaths"), (nc, ncp, "new_cases"), (nd, ndp, "new_deaths")]:
|
# currently infected
|
||||||
|
delay = 21
|
||||||
|
current_infected = np.array(total_cases[delay:]) - np.array(total_deaths[:-delay]) - np.array(total_cases[:-delay])
|
||||||
|
|
||||||
|
ti.plot(time[:-delay], current_infected, label=f"{loc}", marker=".")
|
||||||
|
|
||||||
|
for ax, fig, name in [(tc, tcp, "total_cases"), (td, tdp, "total_deaths"), (nc, ncp, "new_cases"), (nd, ndp, "new_deaths"), (ti, tip, "current_infected")]:
|
||||||
ax.set_yscale("log")
|
ax.set_yscale("log")
|
||||||
ax.set_ylabel(name)
|
ax.set_ylabel(name)
|
||||||
for tick in ax.get_xticklabels():
|
for tick in ax.get_xticklabels():
|
||||||
tick.set_rotation(45)
|
tick.set_rotation(45)
|
||||||
ax.legend(frameon=False)
|
ax.legend(frameon=False)
|
||||||
|
ax.grid(True)
|
||||||
fig.tight_layout()
|
fig.tight_layout()
|
||||||
|
|
||||||
|
|
||||||
fig.savefig(name+".png")
|
fig.savefig(name+".png")
|
||||||
|
|||||||
Reference in New Issue
Block a user