From 5b8d0499c5af670a4c63173c90a6b52970a856b2 Mon Sep 17 00:00:00 2001 From: Benedikt Bastin Date: Tue, 23 Mar 2021 11:49:14 +0100 Subject: [PATCH 1/7] feat: Added annotation for AstraZeneca stop --- plot.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/plot.py b/plot.py index d47c463..fb1147c 100644 --- a/plot.py +++ b/plot.py @@ -359,6 +359,8 @@ def plot_vaccination_bar_graph_total_time_by_week(): 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) + i = 0 + for r1, r2 in zip(bar1, bar2): x = r1.get_x() + r1.get_width() / 2.0 @@ -375,6 +377,22 @@ def plot_vaccination_bar_graph_total_time_by_week(): plt.text(x, hg * 1000, f'{hg:5n} k'.replace('.', ' '), ha='center', va='bottom') + if i == 12: + # Woche der AstraZeneca-Aussetzung + plt.annotate('AstraZeneca-Aussetzung', (x, hg * 1000 + 50000), + xytext=(x, ax.get_ylim()[1]), + arrowprops={ + 'arrowstyle': '->' + }, + bbox={ + 'boxstyle': 'square', + 'fc': 'white', + 'ec': 'black' + }) + + i = i + 1 + + ax.legend(loc='upper left') ax.get_xaxis().set_major_formatter(DateFormatter('%Y-w%W')) ax.get_xaxis().set_major_locator(WeekdayLocator(3, 2)) From bbea5ae53221cbeea847d8d238ea2b1a20a561ca Mon Sep 17 00:00:00 2001 From: Benedikt Bastin Date: Tue, 23 Mar 2021 11:51:07 +0100 Subject: [PATCH 2/7] fix: Refactored saving plots into seperate function --- plot.py | 84 +++++++++++++-------------------------------------------- 1 file changed, 18 insertions(+), 66 deletions(-) diff --git a/plot.py b/plot.py index fb1147c..977ba1a 100644 --- a/plot.py +++ b/plot.py @@ -286,6 +286,14 @@ else: os.mkdir(archive_folder) +def save_plot(archive_plot_filename, latest_plot_filename): + plt.savefig(archive_plot_filename + '.pdf') + plt.savefig(archive_plot_filename + '.png') + plt.savefig(latest_plot_filename + '.pdf') + plt.savefig(latest_plot_filename + '.png') + + print('Created plot {} as pdf and png'.format(archive_plot_filename)) + def plot_vaccination_bar_graph_total_time(): @@ -319,14 +327,9 @@ def plot_vaccination_bar_graph_total_time(): ax.set_xlabel('Datum') ax.set_ylabel('Tägliche Impfungen') - - plt.savefig(archive_plot_filename + '.pdf') - plt.savefig(archive_plot_filename + '.png') - plt.savefig(latest_plot_filename + '.pdf') - plt.savefig(latest_plot_filename + '.png') + save_plot(archive_plot_filename, latest_plot_filename) plt.close() - print('Created plot {} as pdf and png'.format(archive_plot_filename)) plot_vaccination_bar_graph_total_time() @@ -401,15 +404,9 @@ def plot_vaccination_bar_graph_total_time_by_week(): ax.set_xlabel('Datum') ax.set_ylabel('Wöchentliche Impfungen') - - plt.savefig(archive_plot_filename + '.pdf') - plt.savefig(archive_plot_filename + '.png') - plt.savefig(latest_plot_filename + '.pdf') - plt.savefig(latest_plot_filename + '.png') + save_plot(archive_plot_filename, latest_plot_filename) plt.close() - print('Created plot {} as pdf and png'.format(archive_plot_filename)) - plot_vaccination_bar_graph_total_time_by_week() def plot_vaccination_bar_graph_total_time_two_bars(): @@ -447,15 +444,9 @@ def plot_vaccination_bar_graph_total_time_two_bars(): ax.set_xlabel('Datum') ax.set_ylabel('Tägliche Impfungen') - - plt.savefig(archive_plot_filename + '.pdf') - plt.savefig(archive_plot_filename + '.png') - plt.savefig(latest_plot_filename + '.pdf') - plt.savefig(latest_plot_filename + '.png') + save_plot(archive_plot_filename, latest_plot_filename) plt.close() - print('Created plot {} as pdf and png'.format(archive_plot_filename)) - plot_vaccination_bar_graph_total_time_two_bars() def plot_vaccination_bar_graph_compare_both_vaccinations(): @@ -494,15 +485,9 @@ def plot_vaccination_bar_graph_compare_both_vaccinations(): ax.set_xlabel('Datum') ax.set_ylabel('Tägliche Impfungen') - - plt.savefig(archive_plot_filename + '.pdf') - plt.savefig(archive_plot_filename + '.png') - plt.savefig(latest_plot_filename + '.pdf') - plt.savefig(latest_plot_filename + '.png') + save_plot(archive_plot_filename, latest_plot_filename) plt.close() - print('Created plot {} as pdf and png'.format(archive_plot_filename)) - plot_vaccination_bar_graph_compare_both_vaccinations() def plot_cumulative_two_vaccinations(): @@ -540,15 +525,9 @@ def plot_cumulative_two_vaccinations(): ax.set_xlabel('Datum') ax.set_ylabel('Kumulative Impfungen') - - plt.savefig(archive_plot_filename + '.pdf') - plt.savefig(archive_plot_filename + '.png') - plt.savefig(latest_plot_filename + '.pdf') - plt.savefig(latest_plot_filename + '.png') + save_plot(archive_plot_filename, latest_plot_filename) plt.close() - print('Created plot {} as pdf and png'.format(archive_plot_filename)) - plot_cumulative_two_vaccinations() @@ -588,15 +567,9 @@ def plot_cumulative_two_vaccinations_percentage(): ax.set_xlabel('Datum') ax.set_ylabel('Kumulative Impfungen') - - plt.savefig(archive_plot_filename + '.pdf') - plt.savefig(archive_plot_filename + '.png') - plt.savefig(latest_plot_filename + '.pdf') - plt.savefig(latest_plot_filename + '.png') + save_plot(archive_plot_filename, latest_plot_filename) plt.close() - print('Created plot {} as pdf and png'.format(archive_plot_filename)) - plot_cumulative_two_vaccinations_percentage() @@ -638,15 +611,9 @@ def plot_people_between_first_and_second(): ax.set_xlabel('Datum') ax.set_ylabel('Personen zwischen Erst- und Zweitimpfung') - - plt.savefig(archive_plot_filename + '.pdf') - plt.savefig(archive_plot_filename + '.png') - plt.savefig(latest_plot_filename + '.pdf') - plt.savefig(latest_plot_filename + '.png') + save_plot(archive_plot_filename, latest_plot_filename) plt.close() - print('Created plot {} as pdf and png'.format(archive_plot_filename)) - plot_people_between_first_and_second() @@ -689,14 +656,9 @@ def plot_vaccination_rate(): ax.set_xlabel('Datum') ax.set_ylabel('Impfrate [Impfungen/Tag]') - plt.savefig(archive_plot_filename + '.pdf') - plt.savefig(archive_plot_filename + '.png') - plt.savefig(latest_plot_filename + '.pdf') - plt.savefig(latest_plot_filename + '.png') + save_plot(archive_plot_filename, latest_plot_filename) plt.close() - print('Created plot {} as pdf and png'.format(archive_plot_filename)) - plot_vaccination_rate() def plot_vaccination_done_days(): @@ -736,14 +698,9 @@ def plot_vaccination_done_days(): ax.set_xlabel('Datum') ax.set_ylabel('Tage, bis 70 % erreicht sind') - plt.savefig(archive_plot_filename + '.pdf') - plt.savefig(archive_plot_filename + '.png') - plt.savefig(latest_plot_filename + '.pdf') - plt.savefig(latest_plot_filename + '.png') + save_plot(archive_plot_filename, latest_plot_filename) plt.close() - print('Created plot {} as pdf and png'.format(archive_plot_filename)) - plot_vaccination_done_days() def plot_vaccination_done_dates(): @@ -793,14 +750,9 @@ def plot_vaccination_done_dates(): ax.set_xlabel('Datum') ax.set_ylabel('Datum, an dem 70 % erreicht sind') - plt.savefig(archive_plot_filename + '.pdf') - plt.savefig(archive_plot_filename + '.png') - plt.savefig(latest_plot_filename + '.pdf') - plt.savefig(latest_plot_filename + '.png') + save_plot(archive_plot_filename, latest_plot_filename) plt.close() - print('Created plot {} as pdf and png'.format(archive_plot_filename)) - plot_vaccination_done_dates() def render_dashboard(): From 6ee0666039a00247b38c5fd0811d54e52c38daec Mon Sep 17 00:00:00 2001 From: Benedikt Bastin Date: Tue, 23 Mar 2021 12:01:51 +0100 Subject: [PATCH 3/7] fix: Refactored saving plots, seperate function for checking for existing plots --- plot.py | 112 +++++++++++++++++++++++++------------------------------- 1 file changed, 49 insertions(+), 63 deletions(-) diff --git a/plot.py b/plot.py index 977ba1a..7c7ec4a 100644 --- a/plot.py +++ b/plot.py @@ -285,23 +285,33 @@ if os.path.isdir(archive_folder): else: os.mkdir(archive_folder) +def check_recreate_plot(plot_name): -def save_plot(archive_plot_filename, latest_plot_filename): - plt.savefig(archive_plot_filename + '.pdf') - plt.savefig(archive_plot_filename + '.png') - plt.savefig(latest_plot_filename + '.pdf') - plt.savefig(latest_plot_filename + '.png') + archive_plot_filename = '{}/{}'.format(archive_folder, plot_name) - print('Created plot {} as pdf and png'.format(archive_plot_filename)) + if os.path.isfile(archive_plot_filename + '.pdf') and not force_renew: + print('Plot {} already exists'.format(plot_name)) + return False + + return True + +def save_plot(plot_name): + + folders = [archive_folder, site_folder] + file_formats = ['pdf', 'png'] + file_template = '{folder}/{plot_name}.{format}' + + for folder in folders: + for format in file_formats: + plt.savefig(file_template.format(folder=folder, plot_name=plot_name, format=format)) + + print('Created plot {} as {}'.format(plot_name, file_formats)) def plot_vaccination_bar_graph_total_time(): - archive_plot_filename = '{}/vaccination_bar_graph_total_time'.format(archive_folder) - latest_plot_filename = '{}/vaccination_bar_graph_total_time'.format(site_folder) - - if os.path.isfile(archive_plot_filename + '.pdf') and not force_renew: - print('Plot {} already exists'.format(archive_plot_filename)) + plot_name = 'vaccination_bar_graph_total_time' + if not check_recreate_plot(plot_name): return fig, ax = plt.subplots(1) @@ -327,7 +337,7 @@ def plot_vaccination_bar_graph_total_time(): ax.set_xlabel('Datum') ax.set_ylabel('Tägliche Impfungen') - save_plot(archive_plot_filename, latest_plot_filename) + save_plot(plot_name) plt.close() @@ -335,11 +345,8 @@ plot_vaccination_bar_graph_total_time() def plot_vaccination_bar_graph_total_time_by_week(): - archive_plot_filename = '{}/vaccination_bar_graph_total_time_by_week'.format(archive_folder) - latest_plot_filename = '{}/vaccination_bar_graph_total_time_by_week'.format(site_folder) - - if os.path.isfile(archive_plot_filename + '.pdf') and not force_renew: - print('Plot {} already exists'.format(archive_plot_filename)) + plot_name = 'vaccination_bar_graph_total_time_by_week' + if not check_recreate_plot(plot_name): return fig, ax = plt.subplots(1) @@ -404,18 +411,15 @@ def plot_vaccination_bar_graph_total_time_by_week(): ax.set_xlabel('Datum') ax.set_ylabel('Wöchentliche Impfungen') - save_plot(archive_plot_filename, latest_plot_filename) + save_plot(plot_name) plt.close() plot_vaccination_bar_graph_total_time_by_week() def plot_vaccination_bar_graph_total_time_two_bars(): - archive_plot_filename = '{}/vaccination_bar_graph_total_time_two_bars'.format(archive_folder) - latest_plot_filename = '{}/vaccination_bar_graph_total_time_two_bars'.format(site_folder) - - if os.path.isfile(archive_plot_filename + '.pdf') and not force_renew: - print('Plot {} already exists'.format(archive_plot_filename)) + plot_name = 'vaccination_bar_graph_total_time_two_bars' + if not check_recreate_plot(plot_name): return fig, ax = plt.subplots(1) @@ -444,18 +448,15 @@ def plot_vaccination_bar_graph_total_time_two_bars(): ax.set_xlabel('Datum') ax.set_ylabel('Tägliche Impfungen') - save_plot(archive_plot_filename, latest_plot_filename) + save_plot(plot_name) plt.close() plot_vaccination_bar_graph_total_time_two_bars() def plot_vaccination_bar_graph_compare_both_vaccinations(): - archive_plot_filename = '{}/vaccination_bar_graph_compare_both_vaccinations'.format(archive_folder) - latest_plot_filename = '{}/vaccination_bar_graph_compare_both_vaccinations'.format(site_folder) - - if os.path.isfile(archive_plot_filename + '.pdf') and not force_renew: - print('Plot {} already exists'.format(archive_plot_filename)) + plot_name = 'vaccination_bar_graph_compare_both_vaccinations' + if not check_recreate_plot(plot_name): return fig, ax = plt.subplots(1) @@ -485,17 +486,15 @@ def plot_vaccination_bar_graph_compare_both_vaccinations(): ax.set_xlabel('Datum') ax.set_ylabel('Tägliche Impfungen') - save_plot(archive_plot_filename, latest_plot_filename) + save_plot(plot_name) plt.close() plot_vaccination_bar_graph_compare_both_vaccinations() def plot_cumulative_two_vaccinations(): - archive_plot_filename = '{}/cumulative_two_vaccinations'.format(archive_folder) - latest_plot_filename = '{}/cumulative_two_vaccinations'.format(site_folder) - if os.path.isfile(archive_plot_filename + '.pdf') and not force_renew: - print('Plot {} already exists'.format(archive_plot_filename)) + plot_name = 'cumulative_two_vaccinations' + if not check_recreate_plot(plot_name): return fig, ax = plt.subplots(1) @@ -525,18 +524,16 @@ def plot_cumulative_two_vaccinations(): ax.set_xlabel('Datum') ax.set_ylabel('Kumulative Impfungen') - save_plot(archive_plot_filename, latest_plot_filename) + save_plot(plot_name) plt.close() plot_cumulative_two_vaccinations() def plot_cumulative_two_vaccinations_percentage(): - archive_plot_filename = '{}/cumulative_two_vaccinations_percentage'.format(archive_folder) - latest_plot_filename = '{}/cumulative_two_vaccinations_percentage'.format(site_folder) - if os.path.isfile(archive_plot_filename + '.pdf') and not force_renew: - print('Plot {} already exists'.format(archive_plot_filename)) + plot_name = 'cumulative_two_vaccinations_percentage' + if not check_recreate_plot(plot_name): return fig, ax = plt.subplots(1) @@ -567,7 +564,7 @@ def plot_cumulative_two_vaccinations_percentage(): ax.set_xlabel('Datum') ax.set_ylabel('Kumulative Impfungen') - save_plot(archive_plot_filename, latest_plot_filename) + save_plot(plot_name) plt.close() @@ -575,11 +572,9 @@ plot_cumulative_two_vaccinations_percentage() def plot_people_between_first_and_second(): - archive_plot_filename = '{}/people_between_first_and_second'.format(archive_folder) - latest_plot_filename = '{}/people_between_first_and_second'.format(site_folder) - if os.path.isfile(archive_plot_filename + '.pdf') and not force_renew: - print('Plot {} already exists'.format(archive_plot_filename)) + plot_name = 'people_between_first_and_second' + if not check_recreate_plot(plot_name): return fig, ax = plt.subplots(1) @@ -611,7 +606,7 @@ def plot_people_between_first_and_second(): ax.set_xlabel('Datum') ax.set_ylabel('Personen zwischen Erst- und Zweitimpfung') - save_plot(archive_plot_filename, latest_plot_filename) + save_plot(plot_name) plt.close() @@ -619,11 +614,8 @@ plot_people_between_first_and_second() def plot_vaccination_rate(): - archive_plot_filename = '{}/vaccination_rate'.format(archive_folder) - latest_plot_filename = '{}/vaccination_rate'.format(site_folder) - - if os.path.isfile(archive_plot_filename + '.pdf') and not force_renew: - print('Plot {} already exists'.format(archive_plot_filename)) + plot_name = 'vaccination_rate' + if not check_recreate_plot(plot_name): return fig, ax = plt.subplots(1) @@ -656,18 +648,15 @@ def plot_vaccination_rate(): ax.set_xlabel('Datum') ax.set_ylabel('Impfrate [Impfungen/Tag]') - save_plot(archive_plot_filename, latest_plot_filename) + save_plot(plot_name) plt.close() plot_vaccination_rate() def plot_vaccination_done_days(): - archive_plot_filename = '{}/vaccination_done_days'.format(archive_folder) - latest_plot_filename = '{}/vaccination_done_days'.format(site_folder) - - if os.path.isfile(archive_plot_filename + '.pdf') and not force_renew: - print('Plot {} already exists'.format(archive_plot_filename)) + plot_name = 'vaccination_done_days' + if not check_recreate_plot(plot_name): return fig, ax = plt.subplots(1) @@ -698,18 +687,15 @@ def plot_vaccination_done_days(): ax.set_xlabel('Datum') ax.set_ylabel('Tage, bis 70 % erreicht sind') - save_plot(archive_plot_filename, latest_plot_filename) + save_plot(plot_name) plt.close() plot_vaccination_done_days() def plot_vaccination_done_dates(): - archive_plot_filename = '{}/vaccination_done_dates'.format(archive_folder) - latest_plot_filename = '{}/vaccination_done_dates'.format(site_folder) - - if os.path.isfile(archive_plot_filename + '.pdf') and not force_renew: - print('Plot {} already exists'.format(archive_plot_filename)) + plot_name = 'vaccination_done_dates' + if not check_recreate_plot(plot_name): return fig, ax = plt.subplots(1) @@ -750,7 +736,7 @@ def plot_vaccination_done_dates(): ax.set_xlabel('Datum') ax.set_ylabel('Datum, an dem 70 % erreicht sind') - save_plot(archive_plot_filename, latest_plot_filename) + save_plot(plot_name) plt.close() plot_vaccination_done_dates() From 093ee5f0737859b3b516716818d4289caab13c63 Mon Sep 17 00:00:00 2001 From: Benedikt Bastin Date: Tue, 23 Mar 2021 12:14:50 +0100 Subject: [PATCH 4/7] feat: Added SVG as output format and made it default in dashboard --- dashboard_template.xhtml | 10 +++++----- plot.py | 9 +++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/dashboard_template.xhtml b/dashboard_template.xhtml index 35a6eb7..5256a41 100644 --- a/dashboard_template.xhtml +++ b/dashboard_template.xhtml @@ -175,16 +175,16 @@

Plots

{% for fig in figures %}
- - {{ fig['caption'] }} - + + + {{ fig['caption'] }} +
Abbildung {{ fig['index'] }}: {{ fig['caption'] }}
Download als PNG Download als PDF + Download als SVG
{% endfor %} diff --git a/plot.py b/plot.py index 7c7ec4a..0af9e25 100644 --- a/plot.py +++ b/plot.py @@ -37,7 +37,8 @@ print_today = today.isoformat() filename_now = datetime.datetime.now().strftime("%Y%m%d%H%M%S") -force_renew = True +force_renew_plots = False +force_renew_dashboard = True # https://www.tagesschau.de/ausland/europa/ursula-von-der-leyen-zu-corona-impfstoffen-101.html target_date_for_herd_immunity = datetime.date(2021, 9, 22) @@ -289,7 +290,7 @@ def check_recreate_plot(plot_name): archive_plot_filename = '{}/{}'.format(archive_folder, plot_name) - if os.path.isfile(archive_plot_filename + '.pdf') and not force_renew: + if os.path.isfile(archive_plot_filename + '.pdf') and not force_renew_plots: print('Plot {} already exists'.format(plot_name)) return False @@ -298,7 +299,7 @@ def check_recreate_plot(plot_name): def save_plot(plot_name): folders = [archive_folder, site_folder] - file_formats = ['pdf', 'png'] + file_formats = ['pdf', 'png', 'svg'] file_template = '{folder}/{plot_name}.{format}' for folder in folders: @@ -747,7 +748,7 @@ def render_dashboard(): stylesheet_filename = 'site/rki-dashboard.css' stylesheet_archive_filename = 'site/archive/{}/rki-dashboard.css'.format(filename_stand) - if os.path.isfile(dashboard_archive_filename) and not force_renew: + if os.path.isfile(dashboard_archive_filename) and not force_renew_dashboard: print('Dashboard {} already exists'.format(dashboard_archive_filename)) return From 2cbac851669ed4728af32977578baf7cc0101dcb Mon Sep 17 00:00:00 2001 From: Benedikt Bastin Date: Tue, 23 Mar 2021 12:39:25 +0100 Subject: [PATCH 5/7] feat: Added annotation for AstraZeneca stop for multiple plots --- plot.py | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/plot.py b/plot.py index 0af9e25..d7b790a 100644 --- a/plot.py +++ b/plot.py @@ -37,7 +37,7 @@ print_today = today.isoformat() filename_now = datetime.datetime.now().strftime("%Y%m%d%H%M%S") -force_renew_plots = False +force_renew_plots = True force_renew_dashboard = True # https://www.tagesschau.de/ausland/europa/ursula-von-der-leyen-zu-corona-impfstoffen-101.html @@ -309,6 +309,15 @@ def save_plot(plot_name): print('Created plot {} as {}'.format(plot_name, file_formats)) +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') + def plot_vaccination_bar_graph_total_time(): plot_name = 'vaccination_bar_graph_total_time' @@ -338,6 +347,8 @@ def plot_vaccination_bar_graph_total_time(): ax.set_xlabel('Datum') ax.set_ylabel('Tägliche Impfungen') + add_annotations(ax) + save_plot(plot_name) plt.close() @@ -390,7 +401,7 @@ def plot_vaccination_bar_graph_total_time_by_week(): if i == 12: # Woche der AstraZeneca-Aussetzung - plt.annotate('AstraZeneca-Aussetzung', (x, hg * 1000 + 50000), + plt.annotate('AZ-Stopp', (x, hg * 1000 + 50000), xytext=(x, ax.get_ylim()[1]), arrowprops={ 'arrowstyle': '->' @@ -399,7 +410,9 @@ def plot_vaccination_bar_graph_total_time_by_week(): 'boxstyle': 'square', 'fc': 'white', 'ec': 'black' - }) + }, + ha='center') + i = i + 1 @@ -449,6 +462,8 @@ def plot_vaccination_bar_graph_total_time_two_bars(): ax.set_xlabel('Datum') ax.set_ylabel('Tägliche Impfungen') + add_annotations(ax) + save_plot(plot_name) plt.close() @@ -525,6 +540,8 @@ def plot_cumulative_two_vaccinations(): ax.set_xlabel('Datum') ax.set_ylabel('Kumulative Impfungen') + add_annotations(ax) + save_plot(plot_name) plt.close() @@ -565,6 +582,8 @@ def plot_cumulative_two_vaccinations_percentage(): ax.set_xlabel('Datum') ax.set_ylabel('Kumulative Impfungen') + add_annotations(ax) + save_plot(plot_name) plt.close() @@ -607,6 +626,8 @@ def plot_people_between_first_and_second(): ax.set_xlabel('Datum') ax.set_ylabel('Personen zwischen Erst- und Zweitimpfung') + add_annotations(ax) + save_plot(plot_name) plt.close() @@ -649,6 +670,8 @@ def plot_vaccination_rate(): ax.set_xlabel('Datum') ax.set_ylabel('Impfrate [Impfungen/Tag]') + add_annotations(ax) + save_plot(plot_name) plt.close() @@ -688,6 +711,8 @@ def plot_vaccination_done_days(): ax.set_xlabel('Datum') ax.set_ylabel('Tage, bis 70 % erreicht sind') + add_annotations(ax) + save_plot(plot_name) plt.close() @@ -737,6 +762,8 @@ def plot_vaccination_done_dates(): ax.set_xlabel('Datum') ax.set_ylabel('Datum, an dem 70 % erreicht sind') + add_annotations(ax) + save_plot(plot_name) plt.close() From 0020d2b03444f01976a06416ac18c3444de00fbc Mon Sep 17 00:00:00 2001 From: Benedikt Bastin Date: Tue, 23 Mar 2021 12:42:51 +0100 Subject: [PATCH 6/7] feat: Added annotation for current week in weekly plot --- plot.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/plot.py b/plot.py index d7b790a..32fec7a 100644 --- a/plot.py +++ b/plot.py @@ -413,6 +413,19 @@ def plot_vaccination_bar_graph_total_time_by_week(): }, ha='center') + if i == len(bar1) - 1: + plt.annotate('Diese Woche', (x, hg * 1000 + 50000), + xytext=(x, ax.get_ylim()[1]), + arrowprops={ + 'arrowstyle': '->', + 'relpos': (0, 0) + }, + bbox={ + 'boxstyle': 'square', + 'fc': 'white', + 'ec': 'black' + }, + ha='left') i = i + 1 From 4b828cdad993c397b73fc2cd196886c95dfa610f Mon Sep 17 00:00:00 2001 From: Benedikt Bastin Date: Tue, 30 Mar 2021 20:34:13 +0200 Subject: [PATCH 7/7] 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():