Skip to content

Commit 47b5116

Browse files
committed
Let MultiNorm inherit from Norm ABC
1 parent bd8e726 commit 47b5116

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

lib/matplotlib/colors.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,6 +2337,12 @@ def _changed(self):
23372337
"""
23382338
self.callbacks.process('changed')
23392339

2340+
@property
2341+
@abstractmethod
2342+
def n_variables(self):
2343+
# Returns the number of variables supported by this normalization
2344+
pass
2345+
23402346

23412347
class Normalize(Norm):
23422348
"""
@@ -2394,11 +2400,6 @@ def __init__(self, vmin=None, vmax=None, clip=False):
23942400
self._clip = clip
23952401
self._scale = None
23962402

2397-
@property
2398-
def n_variables(self):
2399-
# To be overridden by subclasses with multiple inputs
2400-
return 1
2401-
24022403
@property
24032404
def vmin(self):
24042405
# docstring inherited
@@ -2552,6 +2553,11 @@ def scaled(self):
25522553
# docstring inherited
25532554
return self.vmin is not None and self.vmax is not None
25542555

2556+
@property
2557+
def n_variables(self):
2558+
# docstring inherited
2559+
return 1
2560+
25552561

25562562
class TwoSlopeNorm(Normalize):
25572563
def __init__(self, vcenter, vmin=None, vmax=None):
@@ -3277,7 +3283,7 @@ def inverse(self, value):
32773283
return value
32783284

32793285

3280-
class MultiNorm(Normalize):
3286+
class MultiNorm(Norm):
32813287
"""
32823288
A class which contains multiple scalar norms
32833289
"""
@@ -3442,6 +3448,12 @@ def autoscale(self, A):
34423448
"""
34433449
For each constituent norm, Set *vmin*, *vmax* to min, max of the corresponding
34443450
variate in *A*.
3451+
3452+
Parameters
3453+
----------
3454+
A
3455+
Data, must be of length `n_variables` or be a structured array or scalar
3456+
with `n_variables` fields.
34453457
"""
34463458
with self.callbacks.blocked():
34473459
# Pause callbacks while we are updating so we only get

lib/matplotlib/colors.pyi

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,9 @@ class Norm(ABC):
270270
def autoscale_None(self, A: ArrayLike) -> None: ...
271271
@abstractmethod
272272
def scaled(self) -> bool: ...
273+
@abstractmethod
274+
@property
275+
def n_variables(self) -> int: ...
273276

274277

275278
class Normalize(Norm):
@@ -285,8 +288,6 @@ class Normalize(Norm):
285288
@vmax.setter
286289
def vmax(self, value: float | None) -> None: ...
287290
@property
288-
def n_variables(self) -> int: ...
289-
@property
290291
def clip(self) -> bool: ...
291292
@clip.setter
292293
def clip(self, value: bool) -> None: ...
@@ -307,6 +308,8 @@ class Normalize(Norm):
307308
def autoscale(self, A: ArrayLike) -> None: ...
308309
def autoscale_None(self, A: ArrayLike) -> None: ...
309310
def scaled(self) -> bool: ...
311+
@property
312+
def n_variables(self) -> Literal[1]: ...
310313

311314
class TwoSlopeNorm(Normalize):
312315
def __init__(
@@ -411,7 +414,7 @@ class BoundaryNorm(Normalize):
411414

412415
class NoNorm(Normalize): ...
413416

414-
class MultiNorm(Normalize):
417+
class MultiNorm(Norm):
415418
# Here "type: ignore[override]" is used for functions with a return type
416419
# that differs from the function in the base class.
417420
# i.e. where `MultiNorm` returns a tuple and Normalize returns a `float` etc.
@@ -438,6 +441,11 @@ class MultiNorm(Normalize):
438441
def clip(self, value: ArrayLike | bool) -> None: ...
439442
def __call__(self, value: ArrayLike, clip: ArrayLike | bool | None = ...) -> list: ... # type: ignore[override]
440443
def inverse(self, value: ArrayLike) -> list: ... # type: ignore[override]
444+
def autoscale(self, A: ArrayLike) -> None: ...
445+
def autoscale_None(self, A: ArrayLike) -> None: ...
446+
def scaled(self) -> bool: ...
447+
@property
448+
def n_variables(self) -> int: ...
441449

442450
def rgb_to_hsv(arr: ArrayLike) -> np.ndarray: ...
443451
def hsv_to_rgb(hsv: ArrayLike) -> np.ndarray: ...

0 commit comments

Comments
 (0)