""" 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, pop): 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")