Closed
Description
As noted in #18653, norms created via colors._make_norm_from_scale
do not process values that are passed to inverse
so norm.inverse([0.2, 5, 10])
fails, whereas norm.inverse(np.array([0.2, 5, 10]))
works fine.
@QuLogic noticed this:
Probably because inverse
doesn't pass value
through process_value
like __call__
does. Something like:
diff --git a/lib/matplotlib/colors.py b/lib/matplotlib/colors.py
index e417b8178d..b37ec947fa 100644
--- a/lib/matplotlib/colors.py
+++ b/lib/matplotlib/colors.py
@@ -1449,12 +1449,14 @@ def _make_norm_from_scale(scale_cls, base_norm_cls=None, *, init=None):
t_vmin, t_vmax = self._trf.transform([self.vmin, self.vmax])
if not np.isfinite([t_vmin, t_vmax]).all():
raise ValueError("Invalid vmin or vmax")
+ value, is_scalar = self.process_value(value)
rescaled = value * (t_vmax - t_vmin)
rescaled += t_vmin
- return (self._trf
- .inverted()
- .transform(rescaled)
- .reshape(np.shape(value)))
+ t_value = (self._trf
+ .inverted()
+ .transform(rescaled)
+ .reshape(np.shape(value)))
+ return t_value[0] if is_scalar else t_value
Norm.__name__ = base_norm_cls.__name__
Norm.__qualname__ = base_norm_cls.__qualname__
Maybe it also needs the masking?
Originally posted by @QuLogic in #18653 (comment)