|
|
@ -55,7 +55,7 @@ for country_code, country_data in countries.items():
|
|
|
|
line, = ax.plot(
|
|
|
|
line, = ax.plot(
|
|
|
|
df['cases_change'],
|
|
|
|
df['cases_change'],
|
|
|
|
df['daily_cases_avg'],
|
|
|
|
df['daily_cases_avg'],
|
|
|
|
lw=0.5, label=country_data['name'])
|
|
|
|
lw=0.5, c='b', label=country_data['name'])
|
|
|
|
# select which dates to label
|
|
|
|
# select which dates to label
|
|
|
|
df['month'] = df.index.month
|
|
|
|
df['month'] = df.index.month
|
|
|
|
df['month_change'] = df['month'].diff()
|
|
|
|
df['month_change'] = df['month'].diff()
|
|
|
@ -64,29 +64,30 @@ for country_code, country_data in countries.items():
|
|
|
|
labeldates = pd.concat([df[month_start & mar_onwards], df.tail(1)])
|
|
|
|
labeldates = pd.concat([df[month_start & mar_onwards], df.tail(1)])
|
|
|
|
# date labels
|
|
|
|
# date labels
|
|
|
|
for index, row in labeldates.iterrows():
|
|
|
|
for index, row in labeldates.iterrows():
|
|
|
|
date_text = row.name.strftime(format='%d %b')
|
|
|
|
date_text = row.name.strftime(format='%d/%m')
|
|
|
|
ax.annotate(date_text,
|
|
|
|
ax.annotate(date_text,
|
|
|
|
xy=(row['cases_change'], row['daily_cases_avg']),
|
|
|
|
xy=(row['cases_change'], row['daily_cases_avg']),
|
|
|
|
xycoords='data',
|
|
|
|
xycoords='data',
|
|
|
|
xytext=(0,10),
|
|
|
|
xytext=(-5,-7),
|
|
|
|
textcoords='offset points',
|
|
|
|
textcoords='offset points',
|
|
|
|
ha='center',
|
|
|
|
ha='right',
|
|
|
|
color=line.get_color(),
|
|
|
|
size=8,
|
|
|
|
bbox=dict(boxstyle='square, pad=0.5', alpha=0.7, fc='white', ec='white'))
|
|
|
|
color='k')
|
|
|
|
|
|
|
|
# to use same color as current cuvre: color=line.get_color()
|
|
|
|
|
|
|
|
# to add background: bbox=dict(boxstyle='square, pad=0.5', alpha=0.7, fc='white', ec='white')
|
|
|
|
# date markers
|
|
|
|
# date markers
|
|
|
|
ax.scatter(row['cases_change'], row['daily_cases_avg'], color=line.get_color(), s=4)
|
|
|
|
ax.scatter(row['cases_change'], row['daily_cases_avg'], color='k', s=10)
|
|
|
|
|
|
|
|
# XXX todo add legend for data annotations
|
|
|
|
|
|
|
|
|
|
|
|
plt.axvline(x=0, c='black', lw=1, ls=':')
|
|
|
|
plt.axvline(x=0, c='black', lw=1, ls=':')
|
|
|
|
ax.spines['top'].set_visible(False)
|
|
|
|
ax.spines['top'].set_visible(False)
|
|
|
|
ax.spines['right'].set_visible(False)
|
|
|
|
ax.spines['right'].set_visible(False)
|
|
|
|
|
|
|
|
|
|
|
|
ax.set(ylabel="Daily COVID-19 Cases", xlabel="Increase or decrease in cases per day")
|
|
|
|
ax.set(ylabel="UK Daily COVID-19 Cases", xlabel="Increase or decrease in cases per day")
|
|
|
|
|
|
|
|
|
|
|
|
ax.legend(loc='upper center', ncol=3, bbox_to_anchor=(0.5,1.15))
|
|
|
|
#ax.legend(loc='upper center', ncol=3, bbox_to_anchor=(0.5,1.15))
|
|
|
|
|
|
|
|
|
|
|
|
plt.show()
|
|
|
|
#plt.show()
|
|
|
|
#plt.savefig('tornado_plot.pdf')
|
|
|
|
plt.savefig('tornado_plot.pdf')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# %%
|
|
|
|
# %%
|
|
|
|