Files
coronavis/basics.py
2020-03-30 12:45:14 +02:00

38 lines
1.1 KiB
Python

"""
Plot total cases of countries over time on log scale
"""
import matplotlib.pyplot as pp
def plot(data, countries):
figsize = (10,5)
tcp, tc = pp.subplots(figsize=figsize)
tdp, td = pp.subplots(figsize=figsize)
ncp, nc = pp.subplots(figsize=figsize)
ndp, nd = pp.subplots(figsize=figsize)
for loc in data:
if loc not in countries:
continue
time, new_cases, new_deaths, total_cases, total_deaths = data[loc]
# total cases
tc.plot(time, total_cases, label=f"{loc}", marker=".")
# total deaths
td.plot(time, total_deaths, label=f"{loc}", marker=".")
# new cases
nc.plot(time, new_cases, label=f"{loc}", marker=".")
# new deaths
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")]:
ax.set_yscale("log")
ax.set_ylabel(name)
for tick in ax.get_xticklabels():
tick.set_rotation(45)
ax.legend(frameon=False)
fig.tight_layout()
fig.savefig(name+".png")