new plot: doubling time

This commit is contained in:
fordprefect
2020-04-02 13:28:13 +02:00
parent 3f5fd93a75
commit fedae99553
2 changed files with 35 additions and 1 deletions

View File

@@ -14,7 +14,7 @@ sys.path.append(".")
# countries of interest # countries of interest
countries = ["Germany", "Italy", "Spain", "China", "Japan", "South Korea", "Iran", "United States", "World"] countries = ["Germany", "Italy", "Spain", "China", "Japan", "South Korea", "Iran", "United States", "World"]
# enabled plots # enabled plots
plots = ["basics", "death_per_case", "normalized_to_first_death", "delay_from_china", "delay_from_usa", "normalized_to_ten_cases", "percent_increase"] plots = ["basics", "death_per_case", "normalized_to_first_death", "delay_from_china", "delay_from_usa", "normalized_to_ten_cases", "percent_increase", "doubling_time"]
### ###
def get_data(): def get_data():
"""fetch data from remote, cache locally and reorganize internal data """fetch data from remote, cache locally and reorganize internal data

34
doubling_time.py Normal file
View File

@@ -0,0 +1,34 @@
"""
Plot doubling time
"""
import matplotlib.pyplot as pp
import numpy as np
name="doubling_time"
def moving_average(x, w):
return np.convolve(x, np.ones(w), 'valid') / w
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)
window_size = 3
tchar = moving_average(np.array(new_cases),window_size)/moving_average(np.array(total_cases),window_size)
thalf = np.log(2)/tchar
day_of_100_cases = np.argwhere(np.array(total_cases) > 99)[0][0]
new_time_axis = time[int(window_size/2):-int(window_size/2)]
pp.plot(new_time_axis[50:], thalf[50:], label=f"{loc}", marker=".")
pp.yscale("log")
pp.ylabel("doubling time [days]")
#pp.xlabel("daye reported ten cases")
#pp.xticks(rotation=45)
pp.legend(frameon=False)
pp.grid(which="both", axis="y")
pp.tight_layout()
pp.savefig(name+".png")