Skip to content

Commit 23777b3

Browse files
trygvradtimhoffm
andauthored
Apply suggestions from code review
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
1 parent dbeca30 commit 23777b3

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

lib/matplotlib/colors.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2566,9 +2566,8 @@ def n_components(self):
25662566
This is number of elements of the parameter to ``__call__`` and of
25672567
*vmin*, *vmax*.
25682568
2569-
This class support only a single compoenent, as opposed to `MultiNorm`
2569+
This class support only a single component, as opposed to `MultiNorm`
25702570
which supports multiple components.
2571-
25722571
"""
25732572
return 1
25742573

@@ -3318,28 +3317,22 @@ def __init__(self, norms, vmin=None, vmax=None, clip=False):
33183317
``[vmin, vmax]`` for the constituent norms.
33193318
If a list, each value is assigned to each of the constituent
33203319
norms. Single values are repeated to form a list of appropriate size.
3321-
33223320
"""
3323-
33243321
if cbook.is_scalar_or_string(norms):
33253322
raise ValueError("A MultiNorm must be assigned multiple norms")
33263323

3327-
norms = [*norms]
3328-
for i, n in enumerate(norms):
3329-
if n is None:
3330-
norms[i] = Normalize()
3331-
elif isinstance(n, str):
3332-
scale_cls = _get_scale_cls_from_str(n)
3324+
def resolve(norm):
3325+
if isinstance(norm, str):
3326+
scale_cls = _get_scale_cls_from_str(n)
33333327
norms[i] = mpl.colorizer._auto_norm_from_scale(scale_cls)()
3334-
elif not isinstance(n, Normalize):
3328+
elif isinstance(norm, Normalize):
3329+
return norm
3330+
else:
33353331
raise ValueError(
33363332
"MultiNorm must be assigned multiple norms, where each norm "
3337-
f"is of type `None` `str`, or `Normalize`, not {type(n)}")
3333+
f"is of type `str`, or `Normalize`, not {type(n)}")
33383334

3339-
# Convert the list of norms to a tuple to make it immutable.
3340-
# If there is a use case for swapping a single norm, we can add support for
3341-
# that later
3342-
self._norms = tuple(norms)
3335+
self._norms = tuple(resolve(norm) for norm in norms)
33433336

33443337
self.callbacks = cbook.CallbackRegistry(signals=["changed"])
33453338

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy