From 8c68e871d4fba2eff2c268daa4424040cdc08f6f Mon Sep 17 00:00:00 2001 From: Jonathan Citrin Date: Sat, 11 Jan 2025 13:03:42 -0800 Subject: [PATCH] Plotting QoL improvement. Guard against possible empty plots, which otherwise causes verbose warnings. PiperOrigin-RevId: 714489386 --- torax/plotting/plotruns_lib.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/torax/plotting/plotruns_lib.py b/torax/plotting/plotruns_lib.py index cac1a903..3d3e1ebf 100644 --- a/torax/plotting/plotruns_lib.py +++ b/torax/plotting/plotruns_lib.py @@ -482,12 +482,15 @@ def get_limit(plotdata, attrs, percentile, include_first_timepoint): ) lower_bound = ymin / 1.05 if ymin > 0 else ymin * 1.05 - if cfg.ylim_min_zero: - ax.set_ylim([min(lower_bound, 0), ymax * 1.05]) - else: - ax.set_ylim([lower_bound, ymax * 1.05]) - ax.legend(fontsize=cfg.legend_fontsize) + # Guard against empty data + if ymax != 0 or ymin != 0: # Check for meaningful data range + if cfg.ylim_min_zero: + ax.set_ylim([min(lower_bound, 0), ymax * 1.05]) + else: + ax.set_ylim([lower_bound, ymax * 1.05]) + + ax.legend(fontsize=cfg.legend_fontsize) def get_rho(