-
Notifications
You must be signed in to change notification settings - Fork 0
/
BlogStatusDec7.py
80 lines (56 loc) · 1.66 KB
/
BlogStatusDec7.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# -*- coding: utf-8 -*-
"""
Created on Dec 17 2020
1.
2. Deaths vs cases
@author: Matt Bayer
"""
import os
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import datetime
import covid
#%% Load data
state = covid.read_covid_data_wi('state')
covid.plot_by_age(state)
# rename
col_rename = {'Date': 'Date', 'POS_NEW': 'Cases', 'TEST_NEW': 'Tests', 'DTH_NEW': 'Deaths', 'HOSP_NEW': 'Hospitalizations'}
state = state.rename(columns=col_rename)
#%% Plot deaths vs cases
# contra Trevor Bedford on the national data - this seems to fit better with a
# deaths delay of 12 days (instead of 21) and a CFR of 1.0% (instead of 1.8%).
delay = 12 # days
delay_str = 'Deaths (-'+str(delay)+' days)'
# create delayed death column
deaths = state[['Date', 'Deaths']]
deaths.Date = deaths.Date - datetime.timedelta(days=delay)
deaths = deaths.set_index('Date')
state = state.set_index('Date')
state[delay_str] = deaths
state = state.reset_index()
#%% Plot all cases vs. deaths
CFR = 1.0
savefile = '.\\docs\\assets\\plotly\\Cases-Deaths-WI.html'
fig = covid.plotly_twolines(
state,
delay_str,
'Cases',
plotcolors=['firebrick', 'steelblue', 'rosybrown'],
secondary_scale=1/(CFR/100),
plotlabels = {'title': 'WI Deaths and Cases<br>(assuming CFR '+str(CFR)+'%)',
'yaxis': 'Deaths',
'yaxis_secondary': 'Cases',
},
column1_bar=True,
savefile=savefile,
)
# save_png = '.\\docs\\assets\\Cases-Deaths-WI_2020-12-06.png'
save_png = '.\\docs\\assets\\Cases-Deaths-WI.png'
fig.write_image(
save_png,
width=900,
height=600,
engine='kaleido',
)
os.startfile(save_png)