8000 Updates from code review · matplotlib/matplotlib@a0dd541 · GitHub
[go: up one dir, main page]

Skip to content

Commit a0dd541

Browse files
committed
Updates from code review
Thank you @QuLogic for the feedback
1 parent 78b173e commit a0dd541

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

lib/matplotlib/colors.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3233,7 +3233,7 @@ def __init__(self, norms, vmin=None, vmax=None, clip=False):
32333233
"""
32343234
Parameters
32353235
----------
3236-
norms : List of strings or `Normalize` objects
3236+
norms : List of (str, `Normalize` or None)
32373237
The constituent norms. The list must have a minimum length of 2.
32383238
vmin, vmax : float, None, or list of float or None
32393239
Limits of the constituent norms.
@@ -3248,7 +3248,7 @@ def __init__(self, norms, vmin=None, vmax=None, clip=False):
32483248
32493249
"""
32503250

3251-
if isinstance(norms, str) or not np.iterable(norms):
3251+
if cbook.is_scalar_or_string(norms):
32523252
raise ValueError("A MultiNorm must be assigned multiple norms")
32533253

32543254
norms = [*norms]
@@ -3349,7 +3349,7 @@ def __call__(self, value, clip=None):
33493349
33503350
Returns
33513351
-------
3352-
Data
3352+
List
33533353
Normalized input values as a list of length `n_variables`
33543354
33553355
Notes
@@ -3401,7 +3401,7 @@ def autoscale_None(self, A):
34013401
Parameters
34023402
----------
34033403
A
3404-
Data, must be of length `n_variables` or be an np.ndarray type with
3404+
Data, must be of length `n_variables` or have a data type with
34053405
`n_variables` fields.
34063406
"""
34073407
with self.callbacks.blocked():
@@ -3412,7 +3412,7 @@ def autoscale_None(self, A):
34123412

34133413
def scaled(self):
34143414
"""Return whether both *vmin* and *vmax* are set on all constituent norms"""
3415-
return all([(n.vmin is not None and n.vmax is not None) for n in self.norms])
3415+
return all([n.scaled() for n in self.norms])
34163416

34173417
@staticmethod
34183418
def _iterable_variates_in_data(data, n_variables):
@@ -3430,7 +3430,7 @@ def _iterable_variates_in_data(data, n_variables):
34303430
34313431
Returns
34323432
-------
3433-
list of np.ndarray
3433+
list of np.ndarray
34343434
34353435
"""
34363436
if isinstance(data, np.ndarray) and data.dtype.fields is not None:
@@ -4087,9 +4087,9 @@ def _get_scale_cls_from_str(scale_as_str):
40874087
40884088
Used in the creation of norms from a string to ensure a reasonable error
40894089
in the case where an invalid string is used. This would normally use
4090-
`_api.check_getitem()`, which would produce the error
4091-
> 'not_a_norm' is not a valid value for norm; supported values are
4092-
> 'linear', 'log', 'symlog', 'asinh', 'logit', 'function', 'functionlog'
4090+
`_api.check_getitem()`, which would produce the error:
4091+
'not_a_norm' is not a valid value for norm; supported values are
4092+
'linear', 'log', 'symlog', 'asinh', 'logit', 'function', 'functionlog'.
40934093
which is misleading because the norm keyword also accepts `Normalize` objects.
40944094
40954095
Parameters

lib/matplotlib/tests/test_colors.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,3 +1873,11 @@ def test_multi_norm():
18731873
norm.autoscale([[0, 1, 2, 3], [0.1, 1, 2, 3]])
18741874
assert_array_equal(norm.vmin, [0, 0.1])
18751875
assert_array_equal(norm.vmax, [3, 3])
1876+
1877+
# test autoscale_none
1878+
norm0 = mcolors.TwoSlopeNorm(2, vmin=0, vmax=None)
1879+
norm = mcolors.MultiNorm([norm0, None], vmax=[None, 50])
1880+
norm.autoscale_None([[1, 2, 3, 4, 5], [-50, 1, 0, 1, 500]])
1881+
assert_array_equal(norm([5, 0]), [1, 0.5])
1882+
assert_array_equal(norm.vmin, (0, -50))
1883+
assert_array_equal(norm.vmax, (5, 50))

0 commit comments

Comments
 (0)
0