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

Commitd890452

Browse files
committed
improved consistency of return types for better typing
1 parentd08a84e commitd890452

File tree

4 files changed

+54
-22
lines changed

4 files changed

+54
-22
lines changed

‎lib/matplotlib/colorizer.py‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,10 @@ def get_clim(self):
278278
"""
279279
Return the values (min, max) that are mapped to the colormap limits.
280280
"""
281-
returnself.norm.vmin,self.norm.vmax
281+
ifself.norm.n_components==1:
282+
return (self.norm.vmin, ), (self.norm.vmax, )
283+
else:
284+
returnself.norm.vmin,self.norm.vmax
282285

283286
defchanged(self):
284287
"""
@@ -306,7 +309,10 @@ def vmax(self, vmax):
306309

307310
@property
308311
defclip(self):
309-
returnself.norm.clip
312+
ifself.norm.n_components==1:
313+
return (self.norm.clip, )
314+
else:
315+
returnself.norm.clip
310316

311317
@clip.setter
312318
defclip(self,clip):
@@ -360,8 +366,14 @@ def to_rgba(self, x, alpha=None, bytes=False, norm=True):
360366
defget_clim(self):
361367
"""
362368
Return the values (min, max) that are mapped to the colormap limits.
369+
370+
This function is not available for multivariate data.
363371
"""
364-
returnself._colorizer.get_clim()
372+
ifself._colorizer.norm.n_components>1:
373+
raiseAttributeError("`.get_clim()` is unavailable when using a colormap "
374+
"with multiple components. Use "
375+
"`.colorizer.get_clim()` instead")
376+
returnself.colorizer.norm.vmin,self.colorizer.norm.vmax
365377

366378
defset_clim(self,vmin=None,vmax=None):
367379
"""
@@ -376,9 +388,15 @@ def set_clim(self, vmin=None, vmax=None):
376388
tuple (*vmin*, *vmax*) as a single positional argument.
377389
378390
.. ACCEPTS: (vmin: float, vmax: float)
391+
392+
This function is not available for multivariate data.
379393
"""
380394
# If the norm's limits are updated self.changed() will be called
381395
# through the callbacks attached to the norm
396+
ifself._colorizer.norm.n_components>1:
397+
raiseAttributeError("`.set_clim(vmin, vmax)` is unavailable "
398+
"when using a colormap with multiple components. Use "
399+
"`.colorizer.set_clim(vmin, vmax)` instead")
382400
self._colorizer.set_clim(vmin,vmax)
383401

384402
defget_alpha(self):

‎lib/matplotlib/colorizer.pyi‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Colorizer:
1515
@property
1616
defnorm(self)->colors.Norm: ...
1717
@norm.setter
18-
defnorm(self,norm:colors.Norm|str|tuple[str]|None)->None: ...
18+
defnorm(self,norm:colors.Norm|str|tuple[str, ...]|None)->None: ...
1919
defto_rgba(
2020
self,
2121
x:np.ndarray,
@@ -29,21 +29,21 @@ class Colorizer:
2929
defcmap(self)->colors.Colormap|colors.BivarColormap|colors.MultivarColormap: ...
3030
@cmap.setter
3131
defcmap(self,cmap:colors.Colormap|colors.BivarColormap|colors.MultivarColormap|str|None)->None: ...
32-
defget_clim(self)->tuple[float,float]: ...
33-
defset_clim(self,vmin:float|tuple[float,float]|None= ...,vmax:float|None= ...)->None: ...
32+
defget_clim(self)->tuple[tuple[float|None, ...],tuple[float|None, ...]]: ...
33+
defset_clim(self,vmin:float|tuple[float|None, ...]|None= ...,vmax:float|tuple[float|None, ...]|None= ...)->None: ...
3434
defchanged(self)->None: ...
3535
@property
36-
defvmin(self)->float|tuple[float]|None: ...
36+
defvmin(self)->tuple[float|None, ...]|None: ...
3737
@vmin.setter
38-
defvmin(self,value:float|tuple[float]|None)->None: ...
38+
defvmin(self,value:tuple[float|None, ...]|None)->None: ...
3939
@property
40-
defvmax(self)->float|tuple[float]|None: ...
40+
defvmax(self)->tuple[float|None, ...]|None: ...
4141
@vmax.setter
42-
defvmax(self,value:float|tuple[float]|None)->None: ...
42+
defvmax(self,value:tuple[float|None, ...]|None)->None: ...
4343
@property
44-
defclip(self)->bool|tuple[bool, ...]: ...
44+
defclip(self)->tuple[bool, ...]: ...
4545
@clip.setter
46-
defclip(self,value:ArrayLike|bool)->None: ...
46+
defclip(self,value:ArrayLike|bool|tuple[bool, ...])->None: ...
4747

4848

4949
class_ColorizerInterface:
@@ -57,8 +57,8 @@ class _ColorizerInterface:
5757
bytes:bool= ...,
5858
norm:bool= ...,
5959
)->np.ndarray: ...
60-
defget_clim(self)->tuple[float,float]: ...
61-
defset_clim(self,vmin:float|tuple[float,float]|None=...,vmax:float|None= ...)->None: ...
60+
defget_clim(self)->tuple[float,float]|tuple[tuple[float, ...],tuple[float, ...]]: ...
61+
defset_clim(self,vmin:float|tuple[float,float]|tuple[float|None,...]|None,vmax:float|tuple[float|None, ...]|None= ...)->None: ...
6262
defget_alpha(self)->float|None: ...
6363
defget_cmap(self)->colors.Colormap|colors.BivarColormap|colors.MultivarColormap: ...
6464
defset_cmap(self,cmap:str|colors.Colormap|colors.BivarColormap|colors.MultivarColormap)->None: ...

‎lib/matplotlib/colors.pyi‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,13 @@ class Norm(ABC):
255255
def__init__(self)->None: ...
256256
@property
257257
@abstractmethod
258-
defvmin(self)->float|tuple[float]|None: ...
258+
defvmin(self)->float|tuple[float|None, ...]|None: ...
259259
@property
260260
@abstractmethod
261-
defvmax(self)->float|tuple[float]|None: ...
261+
defvmax(self)->float|tuple[float|None, ...]|None: ...
262262
@property
263263
@abstractmethod
264-
defclip(self)->bool|tuple[bool]: ...
264+
defclip(self)->bool|tuple[bool, ...]: ...
265265
@abstractmethod
266266
def__call__(self,value:np.ndarray,clip:bool|None= ...)->ArrayLike: ...
267267
@abstractmethod

‎lib/matplotlib/tests/test_colors.py‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,16 +1786,30 @@ def test_is_color_like(input, expected):
17861786
assertis_color_like(input)isexpected
17871787

17881788

1789-
deftest_colorizer_vmin_vmax():
1789+
deftest_colorizer_vmin_vmax_clip():
17901790
ca=mcolorizer.Colorizer()
1791-
assertca.vminisNone
1792-
assertca.vmaxisNone
1791+
assertlen(ca.vmin)==1
1792+
assertlen(ca.vmax)==1
1793+
assertca.vmin[0]isNone
1794+
assertca.vmax[0]isNone
17931795
ca.vmin=1
17941796
ca.vmax=3
1795-
assertca.vmin==1.0
1796-
assertca.vmax==3.0
1797+
assertca.vmin==(1.0, )
1798+
assertca.vmax==(3.0, )
17971799
assertca.norm.vmin==1.0
17981800
assertca.norm.vmax==3.0
1801+
assertca.clip== (False, )
1802+
1803+
ca=mcolorizer.Colorizer('BiOrangeBlue')
1804+
assertlen(ca.vmin)==2
1805+
assertlen(ca.vmax)==2
1806+
ca.vmin= (1,2)
1807+
ca.vmax= (3,4)
1808+
assertca.vmin== (1.0,2.0)
1809+
assertca.vmax== (3.0,4.0)
1810+
assertca.norm.vmin== (1.0,2.0)
1811+
assertca.norm.vmax== (3.0,4.0)
1812+
assertca.clip== (False,False)
17991813

18001814

18011815
deftest_LinearSegmentedColormap_from_list_color_alpha_tuple():

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp