Diagrams commissioned for the paper: *The Operational Loops of a Pandemic.* by T. D. Sampson and J. Parikka.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

64 lines
1.4 KiB

# %%
import pandas as pd
import requests
import matplotlib.pyplot as plt
from matplotlib import rc
import json
from scipy import interpolate
import numpy as np
# %% Use LaTeX
rc('text', usetex=True)
# %% Function to convert sizes in cm for figure size
def cm2inch(*tupl):
inch = 2.54
if isinstance(tupl[0], tuple):
return tuple(i/inch for i in tupl[0])
else:
return tuple(i/inch for i in tupl)
# %%
r = requests.get('https://disease.sh/v3/covid-19/historical/fr?lastdays=all')
x = r.json()
#%%
df = pd.DataFrame(x['timeline'])
df.index = pd.to_datetime(df.index)
#df = df.reset_index()
# %%
df['daily_deaths'] = df['deaths'].diff().abs() # dirty trick to prevent negative outliers
df['daily_deaths_avg'] = df['daily_deaths'].rolling(7).mean()
df['death_change'] = df['daily_deaths_avg'].diff()
#df.fillna(value=0, inplace=True)
# %%
df = df.resample('4H').asfreq()
# %%
df = df.interpolate(method='spline', order=5)
# %%
# df['daily_deaths_avg'] = df['daily_deaths'].rolling(14).mean()
# df['death_change'] = df['daily_deaths_avg'].diff()
# %%
fig, ax = plt.subplots(figsize=cm2inch(15,15))
ax.plot(df['death_change'], df['daily_deaths_avg'], lw=1)
#plt.plot(df['death_change'], df['daily_deaths_avg'], 'ob') # dots for debugging
ax.axvline(x=0, c='black', lw=1, ls=':')
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
plt.show()
#%%
#df.plot()
#df.plot(x='death_change', y='tornado')