-
Notifications
You must be signed in to change notification settings - Fork 0
/
national_charts.py
163 lines (137 loc) · 6.32 KB
/
national_charts.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import json
import datetime
import pandas as pd
import numpy as np
import requests
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import matplotlib.ticker as mtick
import matplotlib
df = pd.read_csv('us_daily.csv', index_col=0, parse_dates=True)
df = df[:-1] #remove last row, often zero
matplotlib.rcParams['text.color'] = '#555555'
matplotlib.rcParams['axes.labelcolor'] = '#555555'
matplotlib.rcParams['xtick.color'] = '#555555'
matplotlib.rcParams['ytick.color'] = '#555555'
date_from = datetime.datetime(2020, 4, 1)
df = df[df.index >= date_from]
#######################################################################################
# US National Deaths
#######################################################################################
plt.figure(figsize=(10, 5), dpi=400)
plt.box(on=None)
plt.margins(0)
plt.bar(df.index, df['deathIncrease'], width=0.75,
color='#6688cc', label="Daily Deaths")
plt.plot(df.index, df['deathIncrease_7day'],
color='#EE3333', label="7 Day Average")
plt.ylabel("Daily Deaths")
plt.ylim(0)
plt.legend().get_frame().set_linewidth(0.0)
current_value = df.tail(1)['deathIncrease_7day'].round()[0]
current_date = df.tail(1)['deathIncrease_7day'].index[0]
current_value_percentage = (
df['positiveIncrease_7day']/df['totalTestResultsIncrease_7day']).tail(1)[0]
plt.title('US Daily Deaths - '+'{:%b %-d} - {:,} Deaths Avg / day - {:0.1f}% positive'.format(
current_date, int(current_value), 100 * current_value_percentage))
plt.grid(axis='y', linewidth=0.5)
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%m/%d'))
# Change the tick interval
plt.gca().xaxis.set_major_locator(mdates.MonthLocator(interval=1))
plt.savefig('charts/US Death.png', bbox_inches='tight')
plt.close()
#######################################################################################
# US National Testing
#######################################################################################
plt.figure(figsize=(10, 5), dpi=400)
plt.box(on=None)
plt.margins(0)
plt.bar(df.index, df['totalTestResultsIncrease'],
width=0.75, color='#6688cc', label="Daily Tests")
plt.plot(df.index, df['totalTestResultsIncrease_7day'],
color='#EE3333', label="7 Day Average")
plt.ylabel("Daily Tests Completed")
plt.ylim(0)
plt.legend().get_frame().set_linewidth(0.0)
current_value = df.tail(1)['totalTestResultsIncrease_7day'].round()[0]
current_date = df.tail(1)['totalTestResultsIncrease_7day'].index[0]
current_value_percentage = (
df['positiveIncrease_7day']/df['totalTestResultsIncrease_7day']).tail(1)[0]
plt.title('US Daily Tests Completed - '+'{:%b %-d} - {:,} Tests Avg / day - {:0.1f}% positive'.format(
current_date, int(current_value), 100 * current_value_percentage))
plt.grid(axis='y', linewidth=0.5)
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%m/%d'))
# Change the tick interval
plt.gca().xaxis.set_major_locator(mdates.MonthLocator(interval=1))
plt.savefig('charts/US Tests.png', bbox_inches='tight')
plt.close()
######################################################################################
# US Positive Cases
#######################################################################################
plt.figure(figsize=(10, 5), dpi=400)
plt.box(on=None)
plt.margins(0)
plt.bar(df.index, df['positiveIncrease'], width=0.75,
color='#6688cc', label="Daily Positive Cases")
plt.plot(df.index, df['positiveIncrease_7day'],
color='#EE3333', label="7 Day Average")
plt.ylabel("Positive Cases")
plt.ylim(0)
plt.legend().get_frame().set_linewidth(0.0)
current_value = df.tail(1)['positiveIncrease_7day'].round()[0]
current_date = df.tail(1)['positiveIncrease_7day'].index[0]
current_value_percentage = (
df['positiveIncrease_7day']/df['totalTestResultsIncrease_7day']).tail(1)[0]
plt.title('US Daily Positive Cases - '+'{:%b %-d} - {:,} Cases Avg / day - {:0.1f}% positive'.format(
current_date, int(current_value), 100 * current_value_percentage))
plt.grid(axis='y', linewidth=0.5)
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%m/%d'))
# Change the tick interval
plt.gca().xaxis.set_major_locator(mdates.MonthLocator(interval=1))
plt.savefig('charts/US Positive Cases.png', bbox_inches='tight')
plt.close()
######################################################################################
# US Hospitalization
#######################################################################################
plt.figure(figsize=(10, 5), dpi=400)
plt.box(on=None)
plt.margins(0)
plt.bar(df.index, df['hospitalized'], width=0.75,
color='#6688cc', label="Hospitalized")
plt.plot(df.index, df['hospitalized_7day'],
color='#EE3333', label="7 Day Average")
plt.ylabel("Hospitalized")
plt.legend().get_frame().set_linewidth(0.0)
current_value = df.tail(1)['hospitalized_7day'].round()[0]
current_date = df.tail(1)['hospitalized_7day'].index[0]
plt.title('US Number of COVID-19 Patients in Hospital - ' +
'{:%b %-d} - {:,} Patients'.format(current_date, int(current_value)), fontsize=15)
plt.grid(axis='y', linewidth=0.5)
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%m/%d'))
# Change the tick interval
plt.gca().xaxis.set_major_locator(mdates.MonthLocator(interval=1))
plt.savefig('charts/US Hospitalization.png', bbox_inches='tight')
plt.close()
df = df[:-3] #remote last two rows because often zero
######################################################################################
# US Positive %
#######################################################################################
plt.figure(figsize=(10, 5), dpi=400)
plt.box(on=None)
plt.margins(0)
pos = df['positiveIncrease_7day']/df['totalTestResultsIncrease_7day']
plt.plot(df.index, pos, color='#EE3333', label="7 Day Average")
plt.ylabel("Positive %")
plt.ylim(0)
plt.legend().get_frame().set_linewidth(0.0)
current_date = df.tail(1)['positiveIncrease_7day'].index[0]
current_value_percentage = (pos).tail(1)[0]
plt.title('US Daily Positive Percentage - ' +
'{:%b %-d} - {:0.1f}% positive'.format(current_date, 100 * current_value_percentage))
plt.grid(axis='y', linewidth=0.5)
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%m/%d'))
# Change the tick interval
plt.gca().xaxis.set_major_locator(mdates.MonthLocator(interval=1))
plt.gca().yaxis.set_major_formatter(mtick.PercentFormatter(1.0))
plt.savefig('charts/US Positive Percentage.png', bbox_inches='tight')
plt.close()