percent increase plot added
This commit is contained in:
@@ -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"]
|
plots = ["basics", "death_per_case", "normalized_to_first_death", "delay_from_china", "delay_from_usa", "normalized_to_ten_cases", "percent_increase"]
|
||||||
###
|
###
|
||||||
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
|
||||||
|
|||||||
32
percent_increase.py
Normal file
32
percent_increase.py
Normal 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")
|
||||||
Reference in New Issue
Block a user