From 2b29e2f91599ef5cd8f04b38e6c93c67cefe01e6 Mon Sep 17 00:00:00 2001 From: Benedikt Bastin Date: Tue, 6 Apr 2021 15:25:47 +0200 Subject: [PATCH] fix: Fix NaN in rect heights of weekly vaccination rates --- plot.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/plot.py b/plot.py index f4a7570..70fc909 100644 --- a/plot.py +++ b/plot.py @@ -388,13 +388,18 @@ def plot_vaccination_bar_graph_total_time_by_week(): i = 0 + nan_to_zero = lambda x: 0 if math.isnan(x) else x + 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) + 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) if h1 > 30: plt.text(x, h1 * 500, f'{h1:5n} k'.replace('.', ' '), ha='center', va='center', color='white')