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

Appearance settings

Commit b680e11

Browse filesBrowse files
trygvradksunden
authored andcommitted
Corrections based on feedback from @QuLogic
1 parent 5deb9aa commit b680e11
Copy full SHA for b680e11

File tree

3 files changed

+54
-31
lines changed
Filter options

3 files changed

+54
-31
lines changed

‎lib/matplotlib/colorizer.py

Copy file name to clipboardExpand all lines: lib/matplotlib/colorizer.py
+39-29Lines 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+
import functools
23+
2424
import numpy as np
2525
from numpy import ma
26-
import functools
26+
2727
from matplotlib import _api, colors, cbook, scale, artist
2828
import matplotlib as mpl
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 created base on *norm* and *cmap*.""",
34+
object is created from a *norm* and *cmap*.""",
3535
)
3636

3737

3838
class Colorizer:
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
from matplotlib import cm
227236
in_init = self._cmap is None
228-
cmap = cm._ensure_cmap(cmap)
229-
self._cmap = cmap
237+
self._cmap = cm._ensure_cmap(cmap)
230238
if not in_init:
231239
self.changed() # Things are not set up properly yet.
232240

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

281289
@property
282290
def vmin(self):
283-
return self.get_clim[0]
291+
return self.get_clim()[0]
284292

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

289297
@property
290298
def vmax(self):
291-
return self.get_clim[1]
299+
return self.get_clim()[1]
292300

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

440448
@property
441449
def colorbar(self):
450+
"""
451+
The last colorbar associated with this object. May be None
452+
"""
442453
return self._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-
if colorizer and isinstance(colorizer, Colorizer):
594+
if isinstance(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
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+
"""
623639
def __init__(self, colorizer, **kwargs):
624640
"""
625641
Parameters
626642
----------
627643
colorizer : `.colorizer.Colorizer`
628644
"""
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)
632646
super().__init__(colorizer=colorizer, **kwargs)
633647

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

638652
@colorizer.setter
639653
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)
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

Copy file name to clipboardExpand all lines: lib/matplotlib/contour.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,8 +676,8 @@ def __init__(self, ax, *args,
676676

677677
if colorizer:
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

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_colors.py
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import matplotlib as mpl
1616
import matplotlib.colors as mcolors
1717
import matplotlib.colorbar as mcolorbar
18+
import matplotlib.colorizer as mcolorizer
1819
import matplotlib.pyplot as plt
1920
import matplotlib.scale as mscale
2021
from matplotlib.rcsetup import cycler
@@ -1715,3 +1716,15 @@ def test_to_rgba_array_none_color_with_alpha_param():
17151716
(('C3', 0.5), True)])
17161717
def test_is_color_like(input, expected):
17171718
assert is_color_like(input) is expected
1719+
1720+
1721+
def test_colorizer_vmin_vmax():
1722+
ca = mcolorizer.Colorizer()
1723+
assert ca.vmin is None
1724+
assert ca.vmax is None
1725+
ca.vmin = 1
1726+
ca.vmax = 3
1727+
assert ca.vmin == 1.0
1728+
assert ca.vmax == 3.0
1729+
assert ca.norm.vmin == 1.0
1730+
assert ca.norm.vmax == 3.0

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.