Commit 48345554 authored by Pascal Berger's avatar Pascal Berger
Browse files

added better basic plots

parent 1207fd8b
No preview for this file type
This diff is collapsed.
This diff is collapsed.
......@@ -203,6 +203,10 @@ vaccines_all_series = vaccines_all_series.sort_values()[::-1]
vaccines_all_df = vaccines_all_series.to_frame().reset_index()
vaccines_all_df.columns = ['vaccine', 'doses']
total_doses = vaccines_all_df['doses'].sum()
print(total_doses)
# sort descending and plot
#ax = vaccines_all_series.sort_values(ascending = False).plot(kind='bar', figsize=(15, 8))
#ax = vaccines_all_series.sort_values(ascending = False).plot(kind='bar', figsize=(22, 5))
......@@ -217,18 +221,30 @@ vaccines_all_df.columns = ['vaccine', 'doses']
#ax.set_xlabel('vaccination type')
#ax.set_title('Vaccinations for each vaccine type')
# show plot
px.bar(vaccines_all_df, x='vaccine', y='doses')
# %%
total_doses = vaccines_all_df['doses'].sum()
total_doses
plt = px.bar(vaccines_all_df, x='vaccine', y='doses', title="Administered vaccination doses per vaccination type (" + str(round(total_doses / 1000000000, 3)) + " billion total doses)")
plt.update_layout(
autosize=False,
width=800,
height=500,
margin=dict(l=50, r=50, t=50, b=20),
)
plt.show()
# %%
#ax = vaccines_all_series.sort_values(ascending = False).plot(kind='pie', figsize=(22,5), autopct='%3.1f%%', shadow=True)
#ax.set_title('Vaccinations for each vaccine type')
#ax.set_ylabel('')
plt = px.pie(vaccines_all_df, names='vaccine', values='doses')
plt = px.pie(vaccines_all_df, names='vaccine', values='doses', title="Administered vaccination doses per vaccination type (" + str(round(total_doses / 1000000000, 3)) + " billion total doses)")
plt.update_layout(
autosize=False,
width=800,
height=500,
margin=dict(l=50, r=50, t=50, b=20),
legend_title="vaccine",
)
plt.show()
# %%
......@@ -255,23 +271,40 @@ vac_vaccinated = vac_vaccinated.groupby(by=['date'], dropna=True, as_index=False
# vac_vaccinated = vac_vaccinated.fillna(method='ffill')
# #rolling 7-day average
# vac_vaccinated['daily_vaccinations_rolling'] = vac_vaccinated.daily_vaccinations_cum.rolling(7).mean(skipna=True)
vac_vaccinated['daily_vaccinations_rolling'] = vac_vaccinated.daily_vaccinations.rolling(7).mean(skipna=True)
vac_vaccinated['daily_vaccinations_rolling'] = vac_vaccinated.daily_vaccinations.rolling(7, center=True).mean(skipna=True)
# # vac_vaccinated.people_fully_vaccinated = vac_vaccinated.people_fully_vaccinated.rolling(window=7, center=True).mean()
#plot data
ax = vac_vaccinated.plot.line(x='date', figsize=(22, 5))
# y axis in millions
scale_y = 1e6
ticks_y = ticker.FuncFormatter(lambda x, pos: '{0:g}'.format(x/scale_y))
ax.yaxis.set_major_formatter(ticks_y)
# labels
ax.set_ylabel('vaccinations in millions')
ax.set_xlabel('date')
ax.set_title('Vaccinations over time')
# show plot
# #plot data
# ax = vac_vaccinated.plot.line(x='date', figsize=(22, 5))
# # y axis in millions
# scale_y = 1e6
# ticks_y = ticker.FuncFormatter(lambda x, pos: '{0:g}'.format(x/scale_y))
# ax.yaxis.set_major_formatter(ticks_y)
# # labels
# ax.set_ylabel('vaccinations in millions')
# ax.set_xlabel('date')
# ax.set_title('Vaccinations over time')
# # show plot
# plt.show()
df_melt = vac_vaccinated.melt(id_vars='date', value_vars=['daily_vaccinations', 'daily_vaccinations_rolling'])
plt = px.line(df_melt, x='date' , y='value' , color='variable')
plt.update_layout(
autosize=False,
width=1500,
height=500,
margin=dict(l=50, r=50, t=50, b=20),
title="Daily vaccinations over time",
legend_title="observation legend",
xaxis_title="date",
yaxis_title="daily vaccinations"
)
newnames = {'daily_vaccinations':'daily vaccionations', 'daily_vaccinations_rolling': 'daily vaccinations: 7 day average'}
plt.for_each_trace(lambda t: t.update(name = newnames[t.name],
legendgroup = newnames[t.name],
hovertemplate = t.hovertemplate.replace(t.name, newnames[t.name])
)
)
plt.show()
# print(type(vac_vaccinated.daily_vaccinations_cum.rolling(30)))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment