From 2bfde01966623c2ff43f66d118e10a7c4dd997d2 Mon Sep 17 00:00:00 2001 From: fordprefect Date: Fri, 27 Mar 2020 21:10:42 +0100 Subject: [PATCH] add new plot: normalized to 100 cases (when in most countries the exponential spread lifted off) --- coronavis.py | 2 +- normalized_to_ten_cases.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 normalized_to_ten_cases.py diff --git a/coronavis.py b/coronavis.py index 1a6f983..f89af01 100644 --- a/coronavis.py +++ b/coronavis.py @@ -14,7 +14,7 @@ sys.path.append(".") # countries of interest countries = ["Germany", "Italy", "Spain", "China", "Japan", "South Korea", "Iran", "United States", "World"] # enabled plots -plots = ["basics", "death_per_case", "normalized_to_first_death", "delay_from_china", "delay_from_usa"] +plots = ["basics", "death_per_case", "normalized_to_first_death", "delay_from_china", "delay_from_usa", "normalized_to_ten_cases"] ### def get_data(): """fetch data from remote, cache locally and reorganize internal data diff --git a/normalized_to_ten_cases.py b/normalized_to_ten_cases.py new file mode 100644 index 0000000..a6e0dd5 --- /dev/null +++ b/normalized_to_ten_cases.py @@ -0,0 +1,33 @@ +""" +Plot total cases timeshiftet to first death +""" +import matplotlib.pyplot as pp +import numpy as np +name="normalized_to_100_cases" + +def plot(data, countries): + figsize = (10,5) + for loc in data: + if loc not in countries: + continue + time, new_cases, new_deaths, total_cases, total_deaths = data[loc] + + pp.figure(name, figsize=figsize) + day_of_100_cases = np.argwhere(np.array(total_cases) > 99)[0][0] + new_time_axis = np.arange(len(time)) - day_of_100_cases + pp.plot(new_time_axis, np.array(total_cases), label=f"{loc}", marker=".") + + pp.yscale("log") + pp.xticks(rotation=45) + pp.legend(frameon=False) + axis = pp.axis() + pp.axis([-2, axis[1], 80, axis[3]]) + + pos = [(10, 5e5), (30, 5e5), (50, 5e5), (70, 1e3)] + for i, n in enumerate([1,2,3,7]): + pp.plot([0, axis[1]], [100, np.exp(np.log(2) / n * axis[1])], color="grey", linestyle="--") + pp.text(pos[i][0], pos[i][1], f"doubling every\n{n} days", fontsize=8) + + pp.tight_layout() + + pp.savefig(name+".png")