From 6e935572503dcb2b7303344a6b19f62442bca06f Mon Sep 17 00:00:00 2001 From: Benedikt Bastin Date: Sat, 20 Mar 2021 13:38:51 +0100 Subject: [PATCH] feat: Added annotations for weekly vaccination rate plot --- plot.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/plot.py b/plot.py index 85494df..5710b55 100644 --- a/plot.py +++ b/plot.py @@ -361,10 +361,24 @@ def plot_vaccination_bar_graph_total_time_by_week(): print(type(w[0]), type(f[0])) - ax.bar(w, f, label='Wöchentliche Erstimpfungen', color='blue', width=6.8) - ax.bar(w, s, label='Wöchentliche Zweitimpfungen', color='lightblue', width=6.8, bottom=f) + 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) - #ax.set_ylim([0, np.max(f + s) * 1.1]) + for r1, r2 in zip(bar1, bar2): + + x = r1.get_x() + r1.get_width() / 2.0 + + h1 = math.floor(r1.get_height() / 1000) + h2 = math.floor(r2.get_height() / 1000) + hg = math.floor((r1.get_height() + r2.get_height()) / 1000) + + if h1 > 30: + plt.text(x, h1 * 500, f'{h1:5n} k'.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, hg * 1000, f'{hg:5n} k'.replace('.', ' '), ha='center', va='bottom') ax.legend(loc='upper left') ax.get_xaxis().set_major_formatter(DateFormatter('%Y-w%W'))