11
11
12
12
:doc:`/gallery/color/colormap_reference` for a list of builtin colormaps.
13
13
14
- :ref:`colormap-manipulation` for examples of how to make
15
- colormaps.
14
+ :ref:`colormap-manipulation` for examples of how to make colormaps.
16
15
17
- :ref:`colormaps` an in-depth discussion of choosing
18
- colormaps.
16
+ :ref:`colormaps` for an in-depth discussion of choosing colormaps.
19
17
20
18
:ref:`colormapnorms` for more details about data normalization.
21
19
22
20
"""
23
21
22
+ import functools
23
+
24
24
import numpy as np
25
25
from numpy import ma
26
- import functools
26
+
27
27
from matplotlib import _api ,colors ,cbook ,scale ,artist
28
28
import matplotlib as mpl
29
29
30
30
mpl ._docstring .interpd .update (
31
31
colorizer_doc = """\
32
32
colorizer : `~matplotlib.colorizer.Colorizer` or None, default: None
33
33
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*.""" ,
35
35
)
36
36
37
37
38
38
class Colorizer :
39
39
"""
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
42
43
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
43
52
"""
44
53
def __init__ (self ,cmap = None ,norm = None ):
45
54
@@ -225,8 +234,7 @@ def _set_cmap(self, cmap):
225
234
# bury import to avoid circular imports
226
235
from matplotlib import cm
227
236
in_init = self ._cmap is None
228
- cmap = cm ._ensure_cmap (cmap )
229
- self ._cmap = cmap
237
+ self ._cmap = cm ._ensure_cmap (cmap )
230
238
if not in_init :
231
239
self .changed ()# Things are not set up properly yet.
232
240
@@ -280,15 +288,15 @@ def changed(self):
280
288
281
289
@property
282
290
def vmin (self ):
283
- return self .get_clim [0 ]
291
+ return self .get_clim () [0 ]
284
292
285
293
@vmin .setter
286
294
def vmin (self ,vmin ):
287
295
self .set_clim (vmin = vmin )
288
296
289
297
@property
290
298
def vmax (self ):
291
- return self .get_clim [1 ]
299
+ return self .get_clim () [1 ]
292
300
293
301
@vmax .setter
294
302
def vmax (self ,vmax ):
@@ -439,6 +447,9 @@ def autoscale_None(self):
439
447
440
448
@property
441
449
def colorbar (self ):
450
+ """
451
+ The last colorbar associated with this object. May be None
452
+ """
442
453
return self ._colorizer .colorbar
443
454
444
455
@colorbar .setter
@@ -485,10 +496,8 @@ class _ScalarMappable(_ColorizerInterface):
485
496
"""
486
497
A mixin class to map one or multiple sets of scalar data to RGBA.
487
498
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`.
492
501
"""
493
502
494
503
# _ScalarMappable exists for compatibility with
@@ -582,7 +591,7 @@ def _check_exclusionary_keywords(colorizer, **kwargs):
582
591
583
592
@staticmethod
584
593
def _get_colorizer (cmap ,norm ,colorizer ):
585
- if colorizer and isinstance (colorizer ,Colorizer ):
594
+ if isinstance (colorizer ,Colorizer ):
586
595
_ScalarMappable ._check_exclusionary_keywords (
587
596
Colorizer ,cmap = cmap ,norm = norm
588
597
)
@@ -620,15 +629,20 @@ def _get_colorizer(cmap, norm, colorizer):
620
629
621
630
622
631
class ColorizingArtist (_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
+ """
623
639
def __init__ (self ,colorizer ,** kwargs ):
624
640
"""
625
641
Parameters
626
642
----------
627
643
colorizer : `.colorizer.Colorizer`
628
644
"""
629
- if not isinstance (colorizer ,Colorizer ):
630
- raise ValueError ("A `mpl.colorizer.Colorizer` object must be provided" )
631
-
645
+ _api .check_isinstance (Colorizer ,colorizer = colorizer )
632
646
super ().__init__ (colorizer = colorizer ,** kwargs )
633
647
634
648
@property
@@ -637,18 +651,14 @@ def colorizer(self):
637
651
638
652
@colorizer .setter
639
653
def colorizer (self ,cl ):
640
- if isinstance (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
- raise ValueError ("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 )
647
658
648
659
def _set_colorizer_check_keywords (self ,colorizer ,** kwargs ):
649
660
"""
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.
652
662
"""
653
663
self ._check_exclusionary_keywords (colorizer ,** kwargs )
654
664
self .colorizer = colorizer