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 e7d53e0

Browse filesBrowse files
committed
updated ColorizingArtist.__init__
1 parent 00f6232 commit e7d53e0
Copy full SHA for e7d53e0

File tree

4 files changed

+24
-20
lines changed
Filter options

4 files changed

+24
-20
lines changed

‎lib/matplotlib/artist.py

Copy file name to clipboardExpand all lines: lib/matplotlib/artist.py
+5-18Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,33 +1420,20 @@ def set_mouseover(self, mouseover):
14201420

14211421

14221422
class ColorizingArtist(Artist):
1423-
def __init__(self, norm=None, cmap=None):
1423+
def __init__(self, colorizer):
14241424
"""
14251425
Parameters
14261426
----------
1427-
norm : `colors.Normalize` (or subclass thereof) or str or `cm.Colorizer` or None
1428-
The normalizing object which scales data, typically into the
1429-
interval ``[0, 1]``.
1430-
If a `str`, a `colors.Normalize` subclass is dynamically generated based
1431-
on the scale with the corresponding name.
1432-
If `cm.Colorizer`, the norm an colormap on the `cm.Colorizer` will be used
1433-
If *None*, *norm* defaults to a *colors.Normalize* object which
1434-
initializes its scaling based on the first data processed.
1435-
cmap : str or `~matplotlib.colors.Colormap`
1436-
The colormap used to map normalized data values to RGBA colors.
1427+
colorizer : `colorizer.Colorizer`
14371428
"""
1429+
if not isinstance(colorizer, Colorizer):
1430+
raise ValueError("A `mpl.colorizer.Colorizer` object must be provided")
14381431

14391432
Artist.__init__(self)
14401433

14411434
self._A = None
1442-
if isinstance(norm, Colorizer):
1443-
self.colorizer = norm
1444-
if cmap:
1445-
raise ValueError("Providing a `cm.Colorizer` as the norm while "
1446-
"at the same time as a `cmap` is not supported..")
1447-
else:
1448-
self.colorizer = Colorizer(cmap, norm)
14491435

1436+
self.colorizer = colorizer
14501437
self._id_colorizer = self.colorizer.callbacks.connect('changed', self.changed)
14511438
self.callbacks = cbook.CallbackRegistry(signals=["changed"])
14521439

‎lib/matplotlib/collections.py

Copy file name to clipboardExpand all lines: lib/matplotlib/collections.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ def __init__(self, *,
155155
Remaining keyword arguments will be used to set properties as
156156
``Collection.set_{key}(val)`` for each key-value pair in *kwargs*.
157157
"""
158-
artist.ColorizingArtist.__init__(self, norm, cmap)
158+
159+
artist.ColorizingArtist.__init__(self, colorizer._get_colorizer(cmap, norm))
159160
# list of un-scaled dash patterns
160161
# this is needed scaling the dash pattern by linewidth
161162
self._us_linestyles = [(0, None)]

‎lib/matplotlib/colorizer.py

Copy file name to clipboardExpand all lines: lib/matplotlib/colorizer.py
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,22 @@ def clip(self, clip):
299299
self.norm.clip = clip
300300

301301

302+
def _get_colorizer(cmap, norm):
303+
"""
304+
Passes or creates a Colorizer object.
305+
306+
Allows users to pass a Colorizer as the norm keyword
307+
where a artist.ColorizingArtist is used as the artist.
308+
If a Colorizer object is not passed, a Colorizer is created.
309+
"""
310+
if isinstance(norm, Colorizer):
311+
if cmap:
312+
raise ValueError("Providing a `cm.Colorizer` as the norm while "
313+
"at the same time providing a `cmap` is not supported.")
314+
return norm
315+
return Colorizer(cmap, norm)
316+
317+
302318
class ColorizerShim:
303319

304320
def _scale_norm(self, norm, vmin, vmax):

‎lib/matplotlib/image.py

Copy file name to clipboardExpand all lines: lib/matplotlib/image.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def __init__(self, ax,
258258
interpolation_stage=None,
259259
**kwargs
260260
):
261-
martist.ColorizingArtist.__init__(self, norm, cmap)
261+
martist.ColorizingArtist.__init__(self, colorizer._get_colorizer(cmap, norm))
262262
if origin is None:
263263
origin = mpl.rcParams['image.origin']
264264
_api.check_in_list(["upper", "lower"], origin=origin)

0 commit comments

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