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

Commitb680e11

Browse files
trygvradksunden
authored andcommitted
Corrections based on feedback from@QuLogic
1 parent5deb9aa commitb680e11

File tree

3 files changed

+54
-31
lines changed

3 files changed

+54
-31
lines changed

‎lib/matplotlib/colorizer.py

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,44 @@
1111
1212
:doc:`/gallery/color/colormap_reference` for a list of builtin colormaps.
1313
14-
:ref:`colormap-manipulation` for examples of how to make
15-
colormaps.
14+
:ref:`colormap-manipulation` for examples of how to make colormaps.
1615
17-
:ref:`colormaps` an in-depth discussion of choosing
18-
colormaps.
16+
:ref:`colormaps` for an in-depth discussion of choosing colormaps.
1917
2018
:ref:`colormapnorms` for more details about data normalization.
2119
2220
"""
2321

22+
importfunctools
23+
2424
importnumpyasnp
2525
fromnumpyimportma
26-
importfunctools
26+
2727
frommatplotlibimport_api,colors,cbook,scale,artist
2828
importmatplotlibasmpl
2929

3030
mpl._docstring.interpd.update(
3131
colorizer_doc="""\
3232
colorizer : `~matplotlib.colorizer.Colorizer` or None, default: None
3333
The Colorizer object used to map color to data. If None, a Colorizer
34-
object is createdbase on *norm* and *cmap*.""",
34+
object is createdfrom a *norm* and *cmap*.""",
3535
)
3636

3737

3838
classColorizer:
3939
"""
40-
Class that holds the data to color pipeline
41-
accessible via `.Colorizer.to_rgba` and executed via
40+
Data to color pipeline.
41+
42+
This pipeline is accessible via `.Colorizer.to_rgba` and executed via
4243
the `.Colorizer.norm` and `.Colorizer.cmap` attributes.
44+
45+
Parameters
46+
----------
47+
cmap: colorbar.Colorbar or str or None, default: None
48+
The colormap used to color data.
49+
50+
norm: colors.Normalize or str or None, default: None
51+
The normalization used to normalize the data
4352
"""
4453
def__init__(self,cmap=None,norm=None):
4554

@@ -225,8 +234,7 @@ def _set_cmap(self, cmap):
225234
# bury import to avoid circular imports
226235
frommatplotlibimportcm
227236
in_init=self._cmapisNone
228-
cmap=cm._ensure_cmap(cmap)
229-
self._cmap=cmap
237+
self._cmap=cm._ensure_cmap(cmap)
230238
ifnotin_init:
231239
self.changed()# Things are not set up properly yet.
232240

@@ -280,15 +288,15 @@ def changed(self):
280288

281289
@property
282290
defvmin(self):
283-
returnself.get_clim[0]
291+
returnself.get_clim()[0]
284292

285293
@vmin.setter
286294
defvmin(self,vmin):
287295
self.set_clim(vmin=vmin)
288296

289297
@property
290298
defvmax(self):
291-
returnself.get_clim[1]
299+
returnself.get_clim()[1]
292300

293301
@vmax.setter
294302
defvmax(self,vmax):
@@ -439,6 +447,9 @@ def autoscale_None(self):
439447

440448
@property
441449
defcolorbar(self):
450+
"""
451+
The last colorbar associated with this object. May be None
452+
"""
442453
returnself._colorizer.colorbar
443454

444455
@colorbar.setter
@@ -485,10 +496,8 @@ class _ScalarMappable(_ColorizerInterface):
485496
"""
486497
A mixin class to map one or multiple sets of scalar data to RGBA.
487498
488-
The ScalarMappable applies data normalization before returning RGBA colors
489-
from the given `~matplotlib.colors.Colormap`, or
490-
`~matplotlib.colors.BivarColormap`.
491-
499+
The ScalarMappable applies data normalization before returning RGBA colors from
500+
the given `~matplotlib.colors.Colormap`.
492501
"""
493502

494503
# _ScalarMappable exists for compatibility with
@@ -582,7 +591,7 @@ def _check_exclusionary_keywords(colorizer, **kwargs):
582591

583592
@staticmethod
584593
def_get_colorizer(cmap,norm,colorizer):
585-
ifcolorizerandisinstance(colorizer,Colorizer):
594+
ifisinstance(colorizer,Colorizer):
586595
_ScalarMappable._check_exclusionary_keywords(
587596
Colorizer,cmap=cmap,norm=norm
588597
)
@@ -620,15 +629,20 @@ def _get_colorizer(cmap, norm, colorizer):
620629

621630

622631
classColorizingArtist(_ScalarMappable,artist.Artist):
632+
"""
633+
Base class for artists that make map data to color using a `.colorizer.Colorizer`.
634+
635+
The `.colorizer.Colorizer` applies data normalization before
636+
returning RGBA colors from a `~matplotlib.colors.Colormap`.
637+
638+
"""
623639
def__init__(self,colorizer,**kwargs):
624640
"""
625641
Parameters
626642
----------
627643
colorizer : `.colorizer.Colorizer`
628644
"""
629-
ifnotisinstance(colorizer,Colorizer):
630-
raiseValueError("A `mpl.colorizer.Colorizer` object must be provided")
631-
645+
_api.check_isinstance(Colorizer,colorizer=colorizer)
632646
super().__init__(colorizer=colorizer,**kwargs)
633647

634648
@property
@@ -637,18 +651,14 @@ def colorizer(self):
637651

638652
@colorizer.setter
639653
defcolorizer(self,cl):
640-
ifisinstance(cl,Colorizer):
641-
self._colorizer.callbacks.disconnect(self._id_colorizer)
642-
self._colorizer=cl
643-
self._id_colorizer=cl.callbacks.connect('changed',self.changed)
644-
else:
645-
raiseValueError("colorizer must be a `Colorizer` object, not "
646-
f"{type(cl)}.")
654+
_api.check_isinstance(Colorizer,colorizer=cl)
655+
self._colorizer.callbacks.disconnect(self._id_colorizer)
656+
self._colorizer=cl
657+
self._id_colorizer=cl.callbacks.connect('changed',self.changed)
647658

648659
def_set_colorizer_check_keywords(self,colorizer,**kwargs):
649660
"""
650-
Raises a ValueError if any kwarg is not None while colorizer is not None
651-
Passes or creates a Colorizer object.
661+
Raises a ValueError if any kwarg is not None while colorizer is not None.
652662
"""
653663
self._check_exclusionary_keywords(colorizer,**kwargs)
654664
self.colorizer=colorizer

‎lib/matplotlib/contour.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,8 +676,8 @@ def __init__(self, ax, *args,
676676

677677
ifcolorizer:
678678
self._set_colorizer_check_keywords(colorizer,cmap=cmap,
679-
norm=norm,vmin=vmin,
680-
vmax=vmax,colors=colors)
679+
norm=norm,vmin=vmin,
680+
vmax=vmax,colors=colors)
681681
norm=colorizer.norm
682682
cmap=colorizer.cmap
683683
if (isinstance(norm,mcolors.LogNorm)

‎lib/matplotlib/tests/test_colors.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
importmatplotlibasmpl
1616
importmatplotlib.colorsasmcolors
1717
importmatplotlib.colorbarasmcolorbar
18+
importmatplotlib.colorizerasmcolorizer
1819
importmatplotlib.pyplotasplt
1920
importmatplotlib.scaleasmscale
2021
frommatplotlib.rcsetupimportcycler
@@ -1715,3 +1716,15 @@ def test_to_rgba_array_none_color_with_alpha_param():
17151716
(('C3',0.5),True)])
17161717
deftest_is_color_like(input,expected):
17171718
assertis_color_like(input)isexpected
1719+
1720+
1721+
deftest_colorizer_vmin_vmax():
1722+
ca=mcolorizer.Colorizer()
1723+
assertca.vminisNone
1724+
assertca.vmaxisNone
1725+
ca.vmin=1
1726+
ca.vmax=3
1727+
assertca.vmin==1.0
1728+
assertca.vmax==3.0
1729+
assertca.norm.vmin==1.0
1730+
assertca.norm.vmax==3.0

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp