Tornado plot final version

main
parent e3e1a2cfa0
commit 9554d28e7e

Binary file not shown.

File diff suppressed because it is too large Load Diff

@ -55,7 +55,7 @@ for country_code, country_data in countries.items():
line, = ax.plot(
df['cases_change'],
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
df['month'] = df.index.month
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)])
# date labels
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,
xy=(row['cases_change'], row['daily_cases_avg']),
xycoords='data',
xytext=(0,10),
xytext=(-5,-7),
textcoords='offset points',
ha='center',
color=line.get_color(),
bbox=dict(boxstyle='square, pad=0.5', alpha=0.7, fc='white', ec='white'))
ha='right',
size=8,
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
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=':')
ax.spines['top'].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.savefig('tornado_plot.pdf')
#plt.show()
plt.savefig('tornado_plot.pdf')
# %%

Loading…
Cancel
Save