percent increase plot added

This commit is contained in:
fordprefect
2020-03-30 12:44:35 +02:00
parent 2bfde01966
commit 8af2d915cb
2 changed files with 33 additions and 1 deletions

View File

@@ -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", "normalized_to_ten_cases"]
plots = ["basics", "death_per_case", "normalized_to_first_death", "delay_from_china", "delay_from_usa", "normalized_to_ten_cases", "percent_increase"]
###
def get_data():
"""fetch data from remote, cache locally and reorganize internal data

32
percent_increase.py Normal file
View File

@@ -0,0 +1,32 @@
"""
Plot percentual increase
"""
import matplotlib.pyplot as pp
import numpy as np
name="percent_increase"
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]
# moving average of relative new cases with a window size of 3 days
window_size = 3
increase = moving_average(np.array(new_cases)/np.array(total_cases), window_size) * 100
pp.figure(name, figsize=figsize)
delay = 50 # days
pp.plot(time[int(window_size/2)+delay:-int(window_size/2)], increase[delay:], label=f"{loc}", marker=".")
pp.ylabel("percent increase wrt to previous day")
pp.xticks(rotation=45)
pp.legend(frameon=False)
pp.tight_layout()
pp.savefig(name+".png")
pp.yscale("log")
pp.savefig(name+"log.png")