From 847e59565ba21f1ed9aa41e860d275f2dc1f2654 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Mon, 24 Oct 2022 00:01:01 +0200 Subject: [PATCH] Move empty hexbin fix to make_norm_from_scale. 3d2ffef0 added special-casing to handle empty log-scale hexbins, but the more back-compatible fix is to switch make_norm_from_scale to reproduce the old behavior of setting vmin/vmax to np.ma.masked when autoscaling with an empty array. (Whether that behavior is really better is unclear, but until this is properly investigated, it seems safer to go back to it.) --- lib/matplotlib/axes/_axes.py | 4 +--- lib/matplotlib/colors.py | 4 ++++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 42891ce558c5..8e96209d733f 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -4993,9 +4993,7 @@ def reduce_C_function(C: array) -> float # autoscale the norm with current accum values if it hasn't been set if norm is not None: if norm.vmin is None and norm.vmax is None: - norm.autoscale_None(accum) - norm.vmin = np.ma.masked if norm.vmin is None else norm.vmin - norm.vmax = np.ma.masked if norm.vmax is None else norm.vmax + norm.autoscale(accum) if bins is not None: if not np.iterable(bins): diff --git a/lib/matplotlib/colors.py b/lib/matplotlib/colors.py index f8a18443c9e0..3804a9bbfbe9 100644 --- a/lib/matplotlib/colors.py +++ b/lib/matplotlib/colors.py @@ -1718,10 +1718,14 @@ def inverse(self, value): def autoscale(self, A): # i.e. A[np.isfinite(...)], but also for non-array A's in_trf_domain = np.extract(np.isfinite(self._trf.transform(A)), A) + if in_trf_domain.size == 0: + in_trf_domain = np.ma.masked return super().autoscale(in_trf_domain) def autoscale_None(self, A): in_trf_domain = np.extract(np.isfinite(self._trf.transform(A)), A) + if in_trf_domain.size == 0: + in_trf_domain = np.ma.masked return super().autoscale_None(in_trf_domain) if base_norm_cls is Normalize: