From ef8cab63309ba32a7fba5ff3a1fcadb545d385e0 Mon Sep 17 00:00:00 2001 From: Felix Blanke Date: Fri, 1 Sep 2023 14:46:10 +0200 Subject: [PATCH] Add option to not fix lims in plot --- wsgi.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/wsgi.py b/wsgi.py index b762354..defe430 100644 --- a/wsgi.py +++ b/wsgi.py @@ -96,6 +96,7 @@ def plot( total_targets: tuple[int, ...] = (1500, 2500, 3500), alpha: float | None = None, landesbez_str: str | None = None, + fix_lims: bool = True, ) -> str: fig = plt.figure(dpi=300) @@ -125,7 +126,7 @@ def plot( ls="--", marker="o", lw=1, - color="#e4004e" if bez is None else None, + color="#e4004e" if bez is None or not fix_lims else None, markersize=4, label=bez if bez is not None else "Bundesweit", ) @@ -152,14 +153,15 @@ def plot( plt.title("Teilnahme an Digitaler Beschäftigtenbefragung") plt.ylabel("# Teilnahmen") - max_val = df.sum(axis=1).max().item() + if fix_lims: + max_val = df.sum(axis=1).max().item() - nearest_target = np.array(total_targets, dtype=np.float32) - max_val - nearest_target[nearest_target <= 0] = np.inf - idx = np.argmin(nearest_target) + nearest_target = np.array(total_targets, dtype=np.float32) - max_val + nearest_target[nearest_target <= 0] = np.inf + idx = np.argmin(nearest_target) - ceil_val = max(max_val, total_targets[idx]) - plt.ylim(0, ceil_val * 1.025) + ceil_val = max(max_val, total_targets[idx]) + plt.ylim(0, ceil_val * 1.025) plt.legend() # use timezone offset to center tick labels @@ -184,8 +186,9 @@ def plot( sec_ax.set_ylabel("# Teilnahmen [% Erfolg]") sec_ax.yaxis.set_major_formatter(mtick.PercentFormatter()) - for total_target in total_targets: - plt.axhline(y=total_target, color="#48a9be", linestyle="--") + if fix_lims: + for total_target in total_targets: + plt.axhline(y=total_target, color="#48a9be", linestyle="--") plt.tight_layout()