From 4b828cdad993c397b73fc2cd196886c95dfa610f Mon Sep 17 00:00:00 2001 From: Benedikt Bastin Date: Tue, 30 Mar 2021 20:34:13 +0200 Subject: [PATCH] feat: Refactored annotations, added new partial AstraZeneca stop --- plot.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/plot.py b/plot.py index 32fec7a..3c5cf69 100644 --- a/plot.py +++ b/plot.py @@ -308,15 +308,20 @@ def save_plot(plot_name): print('Created plot {} as {}'.format(plot_name, file_formats)) +def labeled_timeperiod(ax, start, end, text, color='lightgrey'): + centre = start + (end - start) / 2 + ax.axvspan(start, end, color=color, alpha=0.5) + ax.text(centre, ax.get_ylim()[1], text, bbox={ + 'boxstyle': 'square', + 'fc': color, + 'ec': 'black' + }, ha='center') + def add_annotations(ax): - ax.axvspan(datetime.datetime(2021, 3, 15), datetime.datetime(2021, 3, 19), color='lightgrey', alpha=0.5) - ax.text(datetime.datetime(2021, 3, 17), ax.get_ylim()[1], 'AZ-Stopp', bbox={ - 'boxstyle': 'square', - 'fc': 'white', - 'ec': 'black' - }, - ha='center') + labeled_timeperiod(ax, datetime.date(2021, 3, 15), datetime.date(2021, 3, 19), 'AZ-Stopp', 'silver') + labeled_timeperiod(ax, datetime.date(2021, 3, 29), today, 'AZ-Stopp u. 60', 'lightgrey') + def plot_vaccination_bar_graph_total_time():