-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplots.py
234 lines (206 loc) · 6.97 KB
/
plots.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
from preprocessing import *
import plotly.express as px
import plotly.graph_objects as go
import geopandas as gpd
import matplotlib.pyplot as plt
pd.options.plotting.backend = "plotly"
################################
# Call functions and get data #
################################
# cases and deaths base dataframe
cases = cases_data()
# tests data merged with cases df
comple = tests_data()
# regions data
regions = regions_data()
# intensive care data (ΜΕΘ)
meth = intensive_care_data()
# geographic data
mee = geo_data(regions)
# global from second API
global_second = global_with_population()
################################
# Cases with Moving Averages Plot #
################################
def figure_1(cases):
### Make the plot with PlotLy.
fig_1 = go.Figure()
fig_1.add_trace(
go.Line(
x=cases['date'],
y=cases['daily_cases'],
name='Daily Cases'
))
fig_1.add_trace(
go.Line(
x=cases['date'],
y=cases['SMA5'],
name='5 Day Moving Average'
))
fig_1.add_trace(
go.Line(
x=cases['date'],
y=cases['SMA10'],
name='10 Day Moving Average'
))
fig_1['layout'].update(title='Daily Cases in Greece\n with Moving Averages',xaxis=dict(
tickangle=-30),
legend=dict(
yanchor="top",
y=0.99,
xanchor="left",
x=0.01
))
return fig_1
def figure_2(cases):
### Make the plot with PlotLy.
fig_2 = go.Figure()
fig_2.add_trace(
go.Line(
x=cases['date'],
y=cases['daily_deaths'],
name='Daily Deaths'
))
fig_2.add_trace(
go.Line(
x=cases['date'],
y=cases['DSMA5'],
name='5 Day Moving Average'
))
fig_2.add_trace(
go.Line(
x=cases['date'],
y=cases['DSMA10'],
name='10 Day Moving Average'
))
fig_2['layout'].update(title='Daily Deaths in Greece\n with Moving Averages',xaxis=dict(
tickangle=-30),
legend=dict(
yanchor="top",
y=0.99,
xanchor="left",
x=0.01
))
return fig_2
def figure_3(comple):
# Make the plot.
fig_3 = go.Figure()
fig_3.add_trace(
go.Scatter(
x=comple['date'],
y=comple['positivity'],
name='Positivity Rate'
))
fig_3['layout'].update(title='Daily Test Positivity Rate (%)',xaxis=dict(
tickangle=-30
))
return fig_3
def figure_4(comple):
fig_4 = go.Figure()
fig_4.add_trace(
go.Scatter(
x=comple['date'],
y=comple['daily_rapid']+comple['daily_tests'],
name='Total Daily Tests (PCR + Rapid)'
))
fig_4['layout'].update(title='Total Daily Tests (PCR + Rapid)',xaxis=dict(
tickangle=-30
))
return fig_4
def figure_5(meth):
fig_5 = go.Figure()
fig_5.add_trace(
go.Scatter(
x=meth['date'],
y=meth['intensive_care'],
name='Number of Cases in Intensive Care'
))
fig_5['layout'].update(title='Number of Cases in Intensive Care',xaxis=dict(
tickangle=-30
))
return fig_5
def figure_6(cases):
fig_6 = go.Figure()
fig_6.add_trace(
go.Scatter(
x=cases['date'],
y=cases['confirmed'],
name='Cases'
))
fig_6['layout'].update(title='Total Confirmed Cases in Greece',xaxis=dict(
tickangle=-30
))
return fig_6
def figure_7(cases):
fig_7 = go.Figure()
fig_7.add_trace(
go.Scatter(
x=cases['date'],
y=cases['deaths'],
name='Cases'
))
fig_7['layout'].update(title='Total Confirmed Deaths in Greece',xaxis=dict(
tickangle=-30
))
return fig_7
def figure_8(regions):
# Barplot
fig_8 = px.bar(regions.sort_values(by='cases_per_100000_people',ascending = False),
x='area_en', y='cases_per_100000_people',
hover_data=['area_gr', 'cases_per_100000_people','last_updated_at','total_cases','population'],
color='total_cases',
labels={
"area_en": "District",
"cases_per_100000_people": "Cases per 100.000 People",
"last_updated_at": "Data Last Updated at",
"population": "Population",
"total_cases": "Total Cases",
"area_gr": "ΝΟΜΟΣ"
},)
fig_8['layout'].update(title='Cases per 100.000 people by District (Νομοί) - Color is total number of cases',
xaxis=dict(
tickangle=-45
))
return fig_8
plt.style.use('default')
plt.rcParams.update({"figure.facecolor":"#0E1117",
"axes.edgecolor":"#0E1117",
"axes.facecolor":"#0E1117",
"text.color":"white",
"axes.labelcolor":"white",
"xtick.color":"white",
"ytick.color":"white"
})
def figure_9(regions,mee):
fig_9,base = plt.subplots(dpi=200)
base.set_aspect('equal')
mee.plot(color='white',edgecolor='#0E1117',figsize=(10, 10),ax=base)
mee.plot(column='casesper100k',legend=True,cmap='inferno',ax=base,\
legend_kwds={'label':"Cases per 100K Population - by Region (Περιφέρεια)",'orientation':'horizontal'})
base.axis('off')
base.set_title("Last Updated on: {}".format(regions.iloc[-1].last_updated_at),fontsize=5,fontdict={"color":"white"})
return fig_9
def figure_10(global_pop):
fig_10 = go.Figure()
fig_10 = px.bar(global_pop.sort_values(by='Cases-per-100k',ascending = False),
x='Country_Region', y='Cases-per-100k',hover_data=['Cases-per-100k','Confirmed','pop_est'],
labels = {'Country_Region': 'Country',
'Cases-per-100k':'Cases per 100,000 population',
'Confirmed': 'Confirmed Cases',
'pop_est':'Population'})
fig_10['layout'].update(title='Cases per 100K population',
xaxis=dict(
tickangle=-45))
return fig_10
def figure_11(global_pop):
fig_11 = go.Figure()
fig_11 = px.bar(global_pop.sort_values(by='Deaths-per-100k',ascending = False),
x='Country_Region', y='Deaths-per-100k',hover_data=['Deaths-per-100k','Deaths','pop_est'],
labels = {'Country_Region': 'Country',
'Deaths-per-100k':'Deaths per 100,000 population',
'Deaths': 'Confirmed Deaths',
'pop_est':'Population'})
fig_11['layout'].update(title='Deaths per 100K population',
xaxis=dict(
tickangle=-45))
return fig_11