Browse Source

Tornado plot with plt and latex

main
parent
commit
e068614cdf
  1. 26
      tornado/tornado.py

26
tornado/tornado.py

@ -3,8 +3,20 @@
import pandas as pd
import requests
import matplotlib.pyplot as plt
from matplotlib import rc
import json
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')
@ -17,11 +29,11 @@ df = df.reset_index()
# df.index = pd.to_datetime(df.index, dayfirst=True)
# %%
df['daily_deaths'] = df['deaths'].diff()
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()
# %%
# %% test polyfit
df.fillna(value=0, inplace=True)
poly = np.polyfit(df['death_change'].values, df['daily_deaths_avg'].values, 10)
poly_tornado = np.poly1d(poly)(df['death_change'].values)
@ -40,6 +52,14 @@ df['tornado'] = poly_tornado
# %%
# df.drop(columns=['cases', 'deaths', 'recovered'], inplace=True)
# %%
df.plot(x='death_change', y='daily_deaths_avg')
# %%
ax = plt.figure(figsize=cm2inch(15,15), frameon=False)
plt.plot(df['death_change'], df['daily_deaths_avg'])
plt.show()
#%%
#df.plot()

Loading…
Cancel
Save