""" 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, 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] # 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")