Files
coronavis/all_countries.py

34 lines
1.3 KiB
Python

"""
Plot overview plot for each country separately
"""
import matplotlib.pyplot as pp
import numpy as np
import time as time_module
basename="all_"
def plot(data, countries):
figsize = (10,5)
for loc in data:
name = basename+loc
time, new_cases, new_deaths, total_cases, total_deaths = data[loc]
fig, ax1 = pp.subplots(num=name, figsize=figsize)
ax1.plot(time, new_cases, label="raw new cases", color="grey", linestyle="-")
ax1.plot(time[3:-3], np.convolve(new_cases, np.ones((7,))/7, mode="valid"), label="new cases 7day mean", color="orange", linestyle="-", linewidth=2)
ax2 = ax1.twinx()
ax2.plot(time, total_cases, label=f"Total cases", marker="", linestyle="--", color="blue")
#ax1.xticks(rotation=45)
#ax1.set_xlabel("date")
ax1.set_ylabel("new cases")
ax2.set_ylabel("total cases")
fig.legend(frameon=False, loc="upper left", bbox_to_anchor=(0,1), bbox_transform=ax1.transAxes)
pp.title(loc)
fig.tight_layout()
pp.text(0.002,0.005, f"plot generated {time_module.strftime('%Y-%m-%d %H:%M')}, CC-by-sa-nc, origin: dukun.de/corona, datasource: ourworldindata.org/coronavirus-source-data", color="dimgrey", fontsize=8, transform=fig.transFigure)
pp.savefig("ac_"+name+".png")
pp.close(fig)