1
0
Fork 0

fix: Improved readability in weekly plot by switching unit to thousand vaccinations

This commit is contained in:
Benedikt Bastin 2021-06-08 14:34:50 +02:00
parent eef4a6b477
commit 2289168af1
1 changed files with 14 additions and 17 deletions

31
plot.py
View File

@ -348,7 +348,7 @@ def plot_vaccination_bar_graph_total_time_by_week():
plt.title(
'Wöchentliche Impfrate (Erst- und Zweitimpfung übereinander)\n'
'Wöchentliche Impfrate in Tausend (Erst- und Zweitimpfung übereinander)\n'
'Datenquelle: RKI, Stand: {}. Erstellung: {}, Ersteller: Benedikt Bastin, Lizenz: CC BY-SA 4.0\n'.format(
print_stand, print_today
)
@ -358,8 +358,8 @@ def plot_vaccination_bar_graph_total_time_by_week():
w = [w.day(3) for w in data_first_vaccination['vaccinations_by_week'].keys()]
f = list(data_first_vaccination['vaccinations_by_week'].values())
s = list(data_second_vaccination['vaccinations_by_week'].values())
f = np.floor(np.array(list(data_first_vaccination['vaccinations_by_week'].values())) / 1000)
s = np.floor(np.array(list(data_second_vaccination['vaccinations_by_week'].values())) / 1000)
bar1 = ax.bar(w, f, label='Wöchentliche Erstimpfungen', color='blue', width=6.8)
bar2 = ax.bar(w, s, label='Wöchentliche Zweitimpfungen', color='lightblue', width=6.8, bottom=f)
@ -372,24 +372,21 @@ def plot_vaccination_bar_graph_total_time_by_week():
x = r1.get_x() + r1.get_width() / 2.0
rh1 = nan_to_zero(r1.get_height())
rh2 = nan_to_zero(r2.get_height())
h1 = math.floor(rh1 / 1000)
h2 = math.floor(rh2 / 1000)
hg = math.floor((rh1 + rh2) / 1000)
h1 = nan_to_zero(r1.get_height())
h2 = nan_to_zero(r2.get_height())
hg = h1 + h2
if h1 > 30:
plt.text(x, h1 * 500, f'{h1:5n} k'.replace('.', ''), ha='center', va='center', color='white')
plt.text(x, h1 * 0.5, f'{h1:5n}'.replace('.', ''), ha='center', va='center', color='white')
if h2 > 30:
plt.text(x, h1 * 1000 + h2 * 500, f'{h2:5n} k'.replace('.', ''), ha='center', va='center', color='black')
plt.text(x, h1 + h2 * 0.5, f'{h2:5n}'.replace('.', ''), ha='center', va='center', color='black')
plt.text(x, hg * 1000, f'{hg:5n} k'.replace('.', ''), ha='center', va='bottom')
plt.text(x, hg, f'{hg:5n}'.replace('.', ''), ha='center', va='bottom')
if i == 12:
# Woche der AstraZeneca-Aussetzung
plt.annotate('AZ-Stopp', (x, hg * 1000 + 50000),
plt.annotate('AZ-Stopp', (x, hg + 60),
xytext=(x, ax.get_ylim()[1]),
arrowprops={
'arrowstyle': '->'
@ -402,7 +399,7 @@ def plot_vaccination_bar_graph_total_time_by_week():
ha='center')
if i == len(bar1) - 1:
plt.annotate('Diese Woche', (x, hg * 1000 + 50000),
plt.annotate('Diese Woche', (x, hg + 60),
xytext=(x, ax.get_ylim()[1]),
arrowprops={
'arrowstyle': '->',
@ -420,11 +417,11 @@ def plot_vaccination_bar_graph_total_time_by_week():
ax.legend(loc='upper left')
ax.get_xaxis().set_major_formatter(DateFormatter('%Y-w%W'))
ax.get_xaxis().set_major_locator(WeekdayLocator(3, 2))
ax.get_xaxis().set_major_locator(WeekdayLocator(3, 3))
ax.get_yaxis().get_major_formatter().set_scientific(False)
ax.set_xlabel('Datum')
ax.set_ylabel('Wöchentliche Impfungen')
ax.set_ylabel('Wöchentliche Impfungen (in Tausend)')
save_plot(plot_name)
plt.close()
@ -920,7 +917,7 @@ def render_dashboard():
},{
'index': 3,
'filename': 'vaccination_bar_graph_total_time_by_week',
'caption': 'Wöchentliche Impfrate (Erst- und Zweitimpfung übereinander)'
'caption': 'Wöchentliche Impfrate in Tausend (Erst- und Zweitimpfung übereinander)'
},{
'index': 4,
'filename': 'vaccination_bar_graph_total_time_two_bars',