Skip to content

Autoinfer norm bounds. #21989

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,8 @@ def __call__(self, value, clip=None):

result, is_scalar = self.process_value(value)

self.autoscale_None(result)
if self.vmin is None or self.vmax is None:
self.autoscale_None(result)
# Convert at least to float, without losing precision.
(vmin,), _ = self.process_value(self.vmin)
(vmax,), _ = self.process_value(self.vmax)
Expand Down Expand Up @@ -1520,7 +1521,8 @@ def __init__(self, *args, **kwargs):

def __call__(self, value, clip=None):
value, is_scalar = self.process_value(value)
self.autoscale_None(value)
if self.vmin is None or self.vmax is None:
self.autoscale_None(value)
if self.vmin > self.vmax:
raise ValueError("vmin must be less or equal to vmax")
if self.vmin == self.vmax:
Expand Down Expand Up @@ -1555,6 +1557,15 @@ def inverse(self, value):
.reshape(np.shape(value)))
return value[0] if is_scalar else 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)
return super().autoscale(in_trf_domain)

def autoscale_None(self, A):
in_trf_domain = np.extract(np.isfinite(self._trf.transform(A)), A)
return super().autoscale_None(in_trf_domain)

Norm.__name__ = (f"{scale_cls.__name__}Norm" if base_norm_cls is Normalize
else base_norm_cls.__name__)
Norm.__qualname__ = base_norm_cls.__qualname__
Expand Down Expand Up @@ -1603,14 +1614,6 @@ def forward(values: array-like) -> array-like
class LogNorm(Normalize):
"""Normalize a given value to the 0-1 range on a log scale."""

def autoscale(self, A):
# docstring inherited.
super().autoscale(np.ma.array(A, mask=(A <= 0)))

def autoscale_None(self, A):
# docstring inherited.
super().autoscale_None(np.ma.array(A, mask=(A <= 0)))


@make_norm_from_scale(
scale.SymmetricalLogScale,
Expand Down