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 f9b2bf0

Browse filesBrowse files
committed
changed name of new class from Mapper to Colorizer and removed calls to old api
changed name of new class from Mapper to Colorizer Mapper → Colorizer ScalarMappableShim → ColorizerShim ColorableArtist → ColorizingArtist also removed all internal calls using the ColorizerShim api
1 parent e6a7c9b commit f9b2bf0
Copy full SHA for f9b2bf0

File tree

11 files changed

+277
-207
lines changed
Filter options

11 files changed

+277
-207
lines changed

‎lib/matplotlib/artist.py

Copy file name to clipboardExpand all lines: lib/matplotlib/artist.py
+38-27Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,7 +1335,7 @@ def format_cursor_data(self, data):
13351335
# inherit from Artist first and from ScalarMappable second, so
13361336
# Artist.format_cursor_data would always have precedence over
13371337
# ScalarMappable.format_cursor_data.
1338-
return self.mapper._format_cursor_data(data)
1338+
return self.colorizer._format_cursor_data(data)
13391339
else:
13401340
try:
13411341
data[0]
@@ -1378,7 +1378,7 @@ def set_mouseover(self, mouseover):
13781378
mouseover = property(get_mouseover, set_mouseover) # backcompat.
13791379

13801380

1381-
class ColorableArtist(Artist):
1381+
class ColorizingArtist(Artist):
13821382
def __init__(self, norm=None, cmap=None):
13831383
"""
13841384
Parameters
@@ -1397,12 +1397,12 @@ def __init__(self, norm=None, cmap=None):
13971397
Artist.__init__(self)
13981398

13991399
self._A = None
1400-
if isinstance(norm, cm.Mapper):
1401-
self._mapper = norm
1400+
if isinstance(norm, cm.Colorizer):
1401+
self._colorizer = norm
14021402
else:
1403-
self._mapper = cm.Mapper(cmap, norm)
1403+
self._colorizer = cm.Colorizer(cmap, norm)
14041404

1405-
self._id_mapper = self.mapper.callbacks.connect('changed', self.changed)
1405+
self._id_colorizer = self.colorizer.callbacks.connect('changed', self.changed)
14061406
self.callbacks = cbook.CallbackRegistry(signals=["changed"])
14071407

14081408
def set_array(self, A):
@@ -1420,7 +1420,7 @@ def set_array(self, A):
14201420
if A is None:
14211421
self._A = None
14221422
return
1423-
A = cm._ensure_multivariate_data(self.cmap.n_variates, A)
1423+
A = cm._ensure_multivariate_data(self.colorizer.cmap.n_variates, A)
14241424

14251425
A = cbook.safe_masked_invalid(A, copy=True)
14261426
if not np.can_cast(A.dtype, float, "same_kind"):
@@ -1433,38 +1433,49 @@ def set_array(self, A):
14331433
raise TypeError(f"Image data of dtype {A.dtype} cannot be "
14341434
f"converted to a sequence of floats")
14351435
self._A = A
1436-
self.mapper.autoscale_None(A)
1436+
self.colorizer.autoscale_None(A)
1437+
1438+
def get_array(self):
1439+
"""
1440+
Return the array of values, that are mapped to colors.
1441+
1442+
The base class `.VectorMappable` does not make any assumptions on
1443+
the dimensionality and shape of the array.
1444+
"""
1445+
return self._A
14371446

14381447
@property
1439-
def mapper(self):
1440-
return self._mapper
1448+
def colorizer(self):
1449+
return self._colorizer
14411450

1442-
@mapper.setter
1443-
def mapper(self, mapper):
1444-
self._set_mapper(mapper)
1451+
@colorizer.setter
1452+
def colorizer(self, colorizer):
1453+
self._set_colorizer(colorizer)
14451454

1446-
def _set_mapper(self, mapper):
1447-
if isinstance(mapper, cm.Mapper):
1455+
def _set_colorizer(self, colorizer):
1456+
if isinstance(colorizer, cm.Colorizer):
14481457
if self._A is not None:
1449-
if not mapper.n_variates == self.mapper.n_variates:
1450-
raise ValueError('The new Mapper object must have the same'
1458+
if not colorizer.cmap.n_variates == self.colorizer.cmap.n_variates:
1459+
raise ValueError('The new Colorizer object must have the same'
14511460
' number of variates as the existing data.')
14521461
else:
1453-
self.mapper.callbacks.disconnect(self._id_mapper)
1454-
self._mapper = mapper
1455-
self._id_mapper = mapper.callbacks.connect('changed', self.changed)
1462+
self.colorizer.callbacks.disconnect(self._id_colorizer)
1463+
self._colorizer = colorizer
1464+
self._id_colorizer = colorizer.callbacks.connect('changed',
1465+
self.changed)
14561466
self.changed()
14571467
else:
1458-
raise ValueError('Only a Mapper object can be set to mapper.')
1468+
raise ValueError('Only a Colorizer object can be set to colorizer.')
14591469

1460-
def get_array(self):
1470+
def _get_colorizer(self):
14611471
"""
1462-
Return the array of values, that are mapped to colors.
1472+
Function to get the colorizer.
1473+
Useful in edge cases where you want a standalone variable with the colorizer,
1474+
but also want the colorizer to update if the colorizer on the artist changes.
14631475
1464-
The base class `.VectorMappable` does not make any assumptions on
1465-
the dimensionality and shape of the array.
1476+
used in `contour.ContourLabeler.label_colorizer`
14661477
"""
1467-
return self._A
1478+
return self._colorizer
14681479

14691480
def changed(self):
14701481
"""
@@ -1484,7 +1495,7 @@ def format_cursor_data(self, data):
14841495
--------
14851496
get_cursor_data
14861497
"""
1487-
return self.mapper._format_cursor_data(data)
1498+
return self.colorizer._format_cursor_data(data)
14881499

14891500

14901501
def _get_tightbbox_for_layout_only(obj, *args, **kwargs):

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+45-29Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from matplotlib import _api, _docstring, _preprocess_data
3535
from matplotlib.axes._base import (
3636
_AxesBase, _TransformedBoundsLocator, _process_plot_format)
37-
from matplotlib.cm import _ensure_cmap, _ensure_multivariate_params
37+
from matplotlib.cm import _ensure_cmap, _ensure_multivariate_params, Colorizer
3838
from matplotlib.axes._secondary_axes import SecondaryAxis
3939
from matplotlib.container import BarContainer, ErrorbarContainer, StemContainer
4040

@@ -4940,9 +4940,9 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
49404940
collection.set_transform(mtransforms.IdentityTransform())
49414941
if colors is None:
49424942
collection.set_array(c)
4943-
collection.set_cmap(cmap)
4944-
collection.set_norm(norm)
4945-
collection._scale_norm(norm, vmin, vmax)
4943+
collection.colorizer.cmap = cmap
4944+
collection.colorizer.norm = norm
4945+
collection.colorizer._scale_norm(norm, vmin, vmax, collection.get_array())
49464946
else:
49474947
extra_kwargs = {
49484948
'cmap': cmap, 'norm': norm, 'vmin': vmin, 'vmax': vmax
@@ -5266,14 +5266,6 @@ def reduce_C_function(C: array) -> float
52665266
else:
52675267
polygons = [polygon]
52685268

5269-
collection = mcoll.PolyCollection(
5270-
polygons,
5271-
edgecolors=edgecolors,
5272-
linewidths=linewidths,
5273-
offsets=offsets,
5274-
offset_transform=mtransforms.AffineDeltaTransform(self.transData)
5275-
)
5276-
52775269
# Set normalizer if bins is 'log'
52785270
if cbook._str_equal(bins, 'log'):
52795271
if norm is not None:
@@ -5284,6 +5276,26 @@ def reduce_C_function(C: array) -> float
52845276
vmin = vmax = None
52855277
bins = None
52865278

5279+
collection = mcoll.PolyCollection(
5280+
polygons,
5281+
edgecolors=edgecolors,
5282+
linewidths=linewidths,
5283+
offsets=offsets,
5284+
offset_transform=mtransforms.AffineDeltaTransform(self.transData),
5285+
norm=norm,
5286+
cmap=cmap
5287+
)
5288+
5289+
if marginals:
5290+
if vmin is None \
5291+
and vmax is None \
5292+
and not isinstance(norm, mcolors.Normalize)\
5293+
and not isinstance(norm, Colorizer)\
5294+
and 'clim' not in kwargs:
5295+
marginals_share_colorizer = False
5296+
else:
5297+
marginals_share_colorizer = True
5298+
52875299
if bins is not None:
52885300
if not np.iterable(bins):
52895301
minimum, maximum = min(accum), max(accum)
@@ -5293,16 +5305,16 @@ def reduce_C_function(C: array) -> float
52935305
accum = bins.searchsorted(accum)
52945306

52955307
collection.set_array(accum)
5296-
collection.set_cmap(cmap)
5297-
collection.set_norm(norm)
52985308
collection.set_alpha(alpha)
52995309
collection._internal_update(kwargs)
5300-
collection._scale_norm(norm, vmin, vmax)
5310+
collection.colorizer._scale_norm(norm, vmin, vmax, collection.get_array())
53015311

5312+
'''
53025313
# autoscale the norm with current accum values if it hasn't been set
53035314
if norm is not None:
53045315
if collection.norm.vmin is None and collection.norm.vmax is None:
53055316
collection.norm.autoscale()
5317+
'''
53065318

53075319
corners = ((xmin, ymin), (xmax, ymax))
53085320
self.update_datalim(corners)
@@ -5347,24 +5359,28 @@ def reduce_C_function(C: array) -> float
53475359
values = values[mask]
53485360

53495361
trans = getattr(self, f"get_{zname}axis_transform")(which="grid")
5350-
bar = mcoll.PolyCollection(
5351-
verts, transform=trans, edgecolors="face")
5362+
if marginals_share_colorizer:
5363+
bar = mcoll.PolyCollection(
5364+
verts, transform=trans, edgecolors="face",
5365+
norm=collection.colorizer)
5366+
else:
5367+
bar = mcoll.PolyCollection(
5368+
verts, transform=trans, edgecolors="face")
5369+
bar.colorizer.cmap = cmap
5370+
bar.colorizer.norm = norm
53525371
bar.set_array(values)
5353-
bar.set_cmap(cmap)
5354-
bar.set_norm(norm)
53555372
bar.set_alpha(alpha)
53565373
bar._internal_update(kwargs)
53575374
bars.append(self.add_collection(bar, autolim=False))
53585375

53595376
collection.hbar, collection.vbar = bars
53605377

5361-
def on_changed(collection):
5362-
collection.hbar.set_cmap(collection.get_cmap())
5363-
collection.hbar.set_cmap(collection.get_cmap())
5364-
collection.vbar.set_clim(collection.get_clim())
5365-
collection.vbar.set_clim(collection.get_clim())
5378+
if not marginals_share_colorizer:
5379+
def on_changed():
5380+
collection.vbar.set_cmap(collection.get_cmap())
5381+
collection.hbar.set_cmap(collection.get_cmap())
53665382

5367-
collection.callbacks.connect('changed', on_changed)
5383+
collection.callbacks.connect('changed', on_changed)
53685384

53695385
return collection
53705386

@@ -5954,7 +5970,7 @@ def imshow(self, X, cmap=None, norm=None, *, aspect=None,
59545970
if im.get_clip_path() is None:
59555971
# image does not already have clipping set, clip to Axes patch
59565972
im.set_clip_path(self.patch)
5957-
im._scale_norm(norm, vmin, vmax)
5973+
im.colorizer._scale_norm(norm, vmin, vmax, im.get_array())
59585974
im.set_url(url)
59595975

59605976
# update ax.dataLim, and, if autoscaling, set viewLim
@@ -6278,7 +6294,7 @@ def pcolor(self, *args, shading=None, alpha=None, norm=None, cmap=None,
62786294

62796295
collection = mcoll.PolyQuadMesh(
62806296
coords, array=C, cmap=cmap, norm=norm, alpha=alpha, **kwargs)
6281-
collection._scale_norm(norm, vmin, vmax)
6297+
collection.colorizer._scale_norm(norm, vmin, vmax, collection.get_array())
62826298

62836299
# Transform from native to data coordinates?
62846300
t = collection._transform
@@ -6513,7 +6529,7 @@ def pcolormesh(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
65136529
collection = mcoll.QuadMesh(
65146530
coords, antialiased=antialiased, shading=shading,
65156531
array=C, cmap=cmap, norm=norm, alpha=alpha, **kwargs)
6516-
collection._scale_norm(norm, vmin, vmax)
6532+
collection.colorizer._scale_norm(norm, vmin, vmax, collection.get_array())
65176533

65186534
coords = coords.reshape(-1, 2) # flatten the grid structure; keep x, y
65196535

@@ -6713,7 +6729,7 @@ def pcolorfast(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
67136729
ret = im
67146730

67156731
if np.ndim(C) == 2: # C.ndim == 3 is RGB(A) so doesn't need scaling.
6716-
ret._scale_norm(norm, vmin, vmax)
6732+
ret.colorizer._scale_norm(norm, vmin, vmax, C)
67176733

67186734
if ret.get_clip_path() is None:
67196735
# image does not already have clipping set, clip to Axes patch

‎lib/matplotlib/backends/qt_editor/figureoptions.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/qt_editor/figureoptions.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,20 +147,20 @@ def prepare_data(d, init):
147147
labeled_mappables.append((label, mappable))
148148
mappables = []
149149
for label, mappable in labeled_mappables:
150-
cmap = mappable.get_cmap()
150+
cmap = mappable.colorizer.cmap
151151
if isinstance(cmap, mcolors.Colormap):
152152
cmaps = [(cmap, name) for name, cmap in sorted(cm._colormaps.items())]
153153
cvals = cm._colormaps.values()
154154
elif isinstance(cmap, mcolors.BivarColormap):
155155
cmaps = [(cmap, name) for name, cmap in sorted(cm._bivar_colormaps.items())]
156156
cvals = cm._bivar_colormaps.values()
157-
else: # isinstance(mappable.get_cmap(), mcolors.MultivarColormap):
157+
else: # isinstance(mappable.colorizer.cmap, mcolors.MultivarColormap):
158158
cmaps = [(cmap, name) for name, cmap
159159
in sorted(cm._multivar_colormaps.items())]
160160
cvals = cm._multivar_colormaps.values()
161161
if cmap not in cvals:
162162
cmaps = [(cmap, cmap.name), *cmaps]
163-
low, high = mappable.mapper.get_clim()
163+
low, high = mappable.colorizer.get_clim()
164164
if len(low) == 1:
165165
low = low[0]
166166
high = high[0]

0 commit comments

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