add metadata from new columns and make every module fit to use this. add stringence of local measures as background of plot, add vaccination status to plots, mute unreasonable warnings
This commit is contained in:
@@ -6,6 +6,8 @@ from mpl_toolkits.axisartist.parasite_axes import HostAxes, ParasiteAxes
|
||||
import numpy as np
|
||||
import time as time_module
|
||||
import pickle
|
||||
import warnings
|
||||
warnings.filterwarnings("ignore", category=UserWarning)
|
||||
basename="all_"
|
||||
|
||||
# manual y adjustments for new cases
|
||||
@@ -28,10 +30,11 @@ def plot(data, countries, pop, **kwargs):
|
||||
if loc == "International":
|
||||
continue
|
||||
name = basename+loc
|
||||
time, new_cases, new_deaths, total_cases, total_deaths = data[loc]
|
||||
time, new_cases, new_deaths, total_cases, total_deaths, total_vaccinations, stringency_index = data[loc]['time'], data[loc]['new_cases'], data[loc]['new_deaths'], data[loc]['total_cases'], data[loc]['total_deaths'], data[loc]['total_vaccinations'], data[loc]['stringency_index']
|
||||
|
||||
fig, ax1 = pp.subplots(num=name, figsize=figsize)
|
||||
|
||||
|
||||
ax2 = ax1.twinx()
|
||||
ax2.plot(time, np.array(total_deaths)*10, label="Total deaths (x10)", marker="", linestyle="--", color="green")
|
||||
ax2.plot(time, total_cases, label=f"Total cases", marker="", linestyle="-", color="blue")
|
||||
@@ -42,6 +45,10 @@ def plot(data, countries, pop, **kwargs):
|
||||
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)
|
||||
|
||||
if not np.isnan(total_vaccinations[-1]):
|
||||
print(f"{loc} has vaccines, adding to plot")
|
||||
ax2.plot(time, np.array(total_vaccinations), label=f"Total vaccinations", marker="", linestyle="-.", color="crimson")
|
||||
|
||||
# fix lower bound of plot
|
||||
for ax in (ax1, ax2):
|
||||
axis = ax.axis()
|
||||
@@ -50,6 +57,12 @@ def plot(data, countries, pop, **kwargs):
|
||||
axis = [axis[0], axis[1], axis[2], corr[loc]]
|
||||
ax.axis([axis[0], axis[1], -1, axis[3]])
|
||||
|
||||
# fix population
|
||||
#try:
|
||||
# print(loc, pop[loc]['pop'] - metadata[loc]['population'])
|
||||
#except:
|
||||
# pop[loc]['pop'] = metadata[loc]['population']
|
||||
|
||||
# if we know population: plot 500 new cases / 1million inhabitants as a rough measure for comparison
|
||||
# also set color for infection level indicator
|
||||
infection_level_indicator = "grey"
|
||||
@@ -82,6 +95,12 @@ def plot(data, countries, pop, **kwargs):
|
||||
print(f"=====> population unknown for {loc}, skipping plot enhancements")
|
||||
|
||||
|
||||
# stringency of countermeasures as background contourf
|
||||
axbounds = ax1.axis()
|
||||
ax1.contourf(time, [-1, 1e10], [stringency_index]*2, cmap="Greys", alpha=0.3, levels=99)
|
||||
ax1.axis(axbounds)
|
||||
|
||||
|
||||
# disabled for now: put second total-cases-per-million-inhabitants axis besides total-cases-axis
|
||||
if loc in pop and False:
|
||||
# according to https://matplotlib.org/3.2.2/gallery/axisartist/demo_parasite_axes.html
|
||||
@@ -107,6 +126,8 @@ def plot(data, countries, pop, **kwargs):
|
||||
if loc in pop:
|
||||
#pp.title(f"{loc}", population = "+f"{pop[loc]['pop']:,}".replace(",","."))
|
||||
title += ", population = "+f"{pop[loc]['pop']:,}".replace(",",".")
|
||||
if not np.isnan(total_vaccinations[-1]):
|
||||
title += ", vac rate: "+f"{total_vaccinations[-1]/pop[loc]['pop']*100:1.3f}%"
|
||||
ax1.set_title(title)
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user