Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf42d65b

Browse files
trygvradQuLogic
andcommitted
Apply suggestions from code review
Thank you@QuLogicCo-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
1 parent6985111 commitf42d65b

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

‎lib/matplotlib/colors.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3242,13 +3242,13 @@ def __init__(self, norms, vmin=None, vmax=None, clip=False):
32423242
The constituent norms. The list must have a minimum length of 2.
32433243
vmin, vmax : float, None, or list of float or None
32443244
Limits of the constituent norms.
3245-
If a list, eacheachvalue is assigned toone of the constituent
3245+
If a list, each value is assigned toeach of the constituent
32463246
norms. Single values are repeated to form a list of appropriate size.
32473247
32483248
clip : bool or list of bools, default: False
32493249
Determines the behavior for mapping values outside the range
32503250
``[vmin, vmax]`` for the constituent norms.
3251-
If a list, eacheachvalue is assigned toone of the constituent
3251+
If a list, each value is assigned toeach of the constituent
32523252
norms. Single values are repeated to form a list of appropriate size.
32533253
32543254
"""
@@ -3263,6 +3263,10 @@ def __init__(self, norms, vmin=None, vmax=None, clip=False):
32633263
elifisinstance(n,str):
32643264
scale_cls=_get_scale_cls_from_str(n)
32653265
norms[i]=mpl.colorizer._auto_norm_from_scale(scale_cls)()
3266+
elifnotisinstance(n,Normalize):
3267+
raiseValueError(
3268+
"MultiNorm must be assigned multiple norms, where each norm "
3269+
f"is of type `None` `str`, or `Normalize`, not{type(n)}")
32663270

32673271
# Convert the list of norms to a tuple to make it immutable.
32683272
# If there is a use case for swapping a single norm, we can add support for
@@ -3275,8 +3279,7 @@ def __init__(self, norms, vmin=None, vmax=None, clip=False):
32753279
self.vmax=vmax
32763280
self.clip=clip
32773281

3278-
self._id_norms= [n.callbacks.connect('changed',
3279-
self._changed)forninself._norms]
3282+
[n.callbacks.connect('changed',self._changed)forninself._norms]
32803283

32813284
@property
32823285
defn_input(self):
@@ -3348,7 +3351,8 @@ def _changed(self):
33483351
def__call__(self,value,clip=None):
33493352
"""
33503353
Normalize the data and return the normalized data.
3351-
Each variate in the input is assigned to the a constituent norm.
3354+
3355+
Each variate in the input is assigned to the constituent norm.
33523356
33533357
Parameters
33543358
----------
@@ -3381,8 +3385,7 @@ def __call__(self, value, clip=None):
33813385

33823386
definverse(self,value):
33833387
"""
3384-
Maps the normalized value (i.e., index in the colormap) back to image
3385-
data value.
3388+
Map the normalized value (i.e., index in the colormap) back to image data value.
33863389
33873390
Parameters
33883391
----------
@@ -3449,7 +3452,7 @@ def _iterable_variates_in_data(data, n_input):
34493452
"""
34503453
ifisinstance(data,np.ndarray)anddata.dtype.fieldsisnotNone:
34513454
data= [data[descriptor[0]]fordescriptorindata.dtype.descr]
3452-
ifnotlen(data)==n_input:
3455+
iflen(data)!=n_input:
34533456
raiseValueError("The input to this `MultiNorm` must be of shape "
34543457
f"({n_input}, ...), or have a data type with{n_input} "
34553458
"fields.")
@@ -4100,9 +4103,11 @@ def _get_scale_cls_from_str(scale_as_str):
41004103
Returns the scale class from a string.
41014104
41024105
Used in the creation of norms from a string to ensure a reasonable error
4103-
in the case where an invalid string is used. This cannot use
4104-
`_api.check_getitem()`, because the norm keyword accepts arguments
4105-
other than strings.
4106+
in the case where an invalid string is used. This would normally use
4107+
`_api.check_getitem()`, which would produce the error
4108+
> 'not_a_norm' is not a valid value for norm; supported values are
4109+
> 'linear', 'log', 'symlog', 'asinh', 'logit', 'function', 'functionlog'
4110+
which is misleading because the norm keyword also accepts `Normalize` objects.
41064111
41074112
Parameters
41084113
----------

‎lib/matplotlib/colors.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,17 +403,17 @@ class MultiNorm(Normalize):
403403
clip:ArrayLike|bool= ...
404404
)->None: ...
405405
@property
406-
defnorms(self)->tuple: ...
406+
defnorms(self)->tuple[Normalize, ...]: ...
407407
@property# type: ignore[override]
408-
defvmin(self)->tuple[float|None]: ...
408+
defvmin(self)->tuple[float|None, ...]: ...
409409
@vmin.setter
410410
defvmin(self,value:ArrayLike|float|None)->None: ...
411411
@property# type: ignore[override]
412-
defvmax(self)->tuple[float|None]: ...
412+
defvmax(self)->tuple[float|None, ...]: ...
413413
@vmax.setter
414414
defvmax(self,value:ArrayLike|float|None)->None: ...
415415
@property# type: ignore[override]
416-
defclip(self)->tuple[bool]: ...
416+
defclip(self)->tuple[bool, ...]: ...
417417
@clip.setter
418418
defclip(self,value:ArrayLike|bool)->None: ...
419419
def__call__(self,value:ArrayLike,clip:ArrayLike|bool|None= ...)->list: ...# type: ignore[override]

‎lib/matplotlib/tests/test_colors.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,6 +1840,10 @@ def test_multi_norm():
18401840
withpytest.raises(ValueError,
18411841
match="Invalid norm str name"):
18421842
mcolors.MultiNorm(["bad_norm_name"])
1843+
withpytest.raises(ValueError,
1844+
match="MultiNorm must be assigned multiple norms, "
1845+
"where each norm is of type `None`"):
1846+
mcolors.MultiNorm([4])
18431847

18441848
# test get vmin, vmax
18451849
norm=mpl.colors.MultiNorm(['linear','log'])

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp