delay from china in days
This commit is contained in:
71
delay_from_china.py
Normal file
71
delay_from_china.py
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
"""
|
||||||
|
Plot delay of countries
|
||||||
|
"""
|
||||||
|
import matplotlib.pyplot as pp
|
||||||
|
import numpy as np
|
||||||
|
name="delay"
|
||||||
|
|
||||||
|
def plot(data, countries):
|
||||||
|
for loc in data:
|
||||||
|
if loc not in countries:
|
||||||
|
continue
|
||||||
|
time, new_cases, new_deaths, total_cases, total_deaths = data[loc]
|
||||||
|
|
||||||
|
pp.figure(name)
|
||||||
|
day_of_above_hundred_cases = np.argwhere(np.array(total_cases) > 100)[0][0]
|
||||||
|
|
||||||
|
new_time_axis = np.arange(len(time)) - day_of_above_hundred_cases
|
||||||
|
pp.plot(new_time_axis, np.array(total_cases), label=f"{loc} - {day_of_above_hundred_cases}", marker=".")
|
||||||
|
|
||||||
|
pp.yscale("log")
|
||||||
|
pp.xticks(rotation=45)
|
||||||
|
pp.legend(frameon=False)
|
||||||
|
pp.tight_layout()
|
||||||
|
|
||||||
|
pp.savefig(name+".png")
|
||||||
|
|
||||||
|
# plot delay
|
||||||
|
pp.clf()
|
||||||
|
delay = {}
|
||||||
|
tcases = [50, 100, 500, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 12500, 15000, 17500,
|
||||||
|
20000, 22500, 25000, 27500,
|
||||||
|
30000, 32500, 35000, 37500,
|
||||||
|
40000, 42500, 45000, 47500,
|
||||||
|
50000, 52500, 55000, 57500,
|
||||||
|
60000, 62500, 65000, 67500,
|
||||||
|
70000, 72500, 75000, 77500,
|
||||||
|
80000]
|
||||||
|
|
||||||
|
time_china = data["China"][0]
|
||||||
|
case_date_china = np.array([time_china[np.argwhere(np.array(data["China"][3]) > cases)[0][0]] for cases in tcases])
|
||||||
|
total_cases_china = data["China"][3]
|
||||||
|
for loc in data:
|
||||||
|
if loc not in countries:
|
||||||
|
continue
|
||||||
|
if loc in ["China", "World"]:
|
||||||
|
continue
|
||||||
|
this_delay = []
|
||||||
|
for i, cases in enumerate(tcases):
|
||||||
|
try:
|
||||||
|
case_date = data[loc][0][np.argwhere(np.array(data[loc][3]) > cases)[0][0]]
|
||||||
|
except:
|
||||||
|
this_delay.append(np.nan)
|
||||||
|
continue
|
||||||
|
#case_date = np.array([time_china[np.argwhere(np.array(data[loc][3]) > cases)[0][0]] for cases in tcases])
|
||||||
|
|
||||||
|
this_delay.append((case_date_china[i] - case_date).days)
|
||||||
|
|
||||||
|
delay[loc] = this_delay
|
||||||
|
|
||||||
|
sort = np.argsort(delay)
|
||||||
|
|
||||||
|
for loc in delay:
|
||||||
|
pp.plot(tcases, delay[loc], label=loc, marker=".")
|
||||||
|
#pp.plot(np.arange(len(delay)), np.array(delay)[sort] - np.min(delay), marker="o", linestyle="")
|
||||||
|
#pp.xticks(ticks=np.arange(len(delay)), labels=np.array(d_loc)[sort])
|
||||||
|
pp.xticks(rotation=45)
|
||||||
|
pp.legend(frameon=False)
|
||||||
|
pp.xlabel("total cases")
|
||||||
|
pp.ylabel("delay to china [days]")
|
||||||
|
pp.tight_layout()
|
||||||
|
pp.savefig(name+"num.png")
|
||||||
Reference in New Issue
Block a user