From f9cefde0e9ccee6abbc91b6dfc0244560253a945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Robert?= Date: Tue, 5 Apr 2022 21:06:29 +0200 Subject: [PATCH] BUG: fix a bug where setting zmin/zmax on a 2D plot with symlog norm would cause an undesired change in linthresh --- yt/visualization/base_plot_types.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/yt/visualization/base_plot_types.py b/yt/visualization/base_plot_types.py index aec211d5ebb..9ab6adfaafe 100644 --- a/yt/visualization/base_plot_types.py +++ b/yt/visualization/base_plot_types.py @@ -219,18 +219,19 @@ def _init_image(self, data, cbnorm, cblinthresh, cmap, extent, aspect): if cbnorm == "symlog": # if cblinthresh is not specified, try to come up with a reasonable default - min_abs_val, max_abs_val = np.sort(np.abs((zmin, zmax))) + min_abs_val, max_abs_val = np.sort( + np.abs((np.nanmin(data), np.nanmax(data))) + ) if cblinthresh is not None: - pass + if zmin * zmax > 0 and cblinthresh < min_abs_val: + warnings.warn( + f"Cannot set a symlog norm with linear threshold {cblinthresh} " + f"lower than the minimal absolute data value {min_abs_val} . " + "Switching to log norm." + ) + cbnorm = "log10" elif min_abs_val > 0: cblinthresh = min_abs_val - elif zmin * zmax > 0 and cblinthresh < min_abs_val: - warnings.warn( - f"Cannot set a symlog norm with linear threshold {cblinthresh} " - f"lower than the minimal absolute data value {min_abs_val} . " - "Switching to log norm." - ) - cbnorm = "log10" else: cblinthresh = max_abs_val / 1000 if cblinthresh is None: