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 32e0256

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 7f6fe56 commit 32e0256
Copy full SHA for 32e0256

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
@@ -1354,7 +1354,7 @@ def format_cursor_data(self, data):
13541354
# inherit from Artist first and from ScalarMappable second, so
13551355
# Artist.format_cursor_data would always have precedence over
13561356
# ScalarMappable.format_cursor_data.
1357-
return self.mapper._format_cursor_data(data)
1357+
return self.colorizer._format_cursor_data(data)
13581358
else:
13591359
try:
13601360
data[0]
@@ -1397,7 +1397,7 @@ def set_mouseover(self, mouseover):
13971397
mouseover = property(get_mouseover, set_mouseover) # backcompat.
13981398

13991399

1400-
class ColorableArtist(Artist):
1400+
class ColorizingArtist(Artist):
14011401
def __init__(self, norm=None, cmap=None):
14021402
"""
14031403
Parameters
@@ -1416,12 +1416,12 @@ def __init__(self, norm=None, cmap=None):
14161416
Artist.__init__(self)
14171417

14181418
self._A = None
1419-
if isinstance(norm, cm.Mapper):
1420-
self._mapper = norm
1419+
if isinstance(norm, cm.Colorizer):
1420+
self._colorizer = norm
14211421
else:
1422-
self._mapper = cm.Mapper(cmap, norm)
1422+
self._colorizer = cm.Colorizer(cmap, norm)
14231423

1424-
self._id_mapper = self.mapper.callbacks.connect('changed', self.changed)
1424+
self._id_colorizer = self.colorizer.callbacks.connect('changed', self.changed)
14251425
self.callbacks = cbook.CallbackRegistry(signals=["changed"])
14261426

14271427
def set_array(self, A):
@@ -1439,7 +1439,7 @@ def set_array(self, A):
14391439
if A is None:
14401440
self._A = None
14411441
return
1442-
A = cm._ensure_multivariate_data(self.cmap.n_variates, A)
1442+
A = cm._ensure_multivariate_data(self.colorizer.cmap.n_variates, A)
14431443

14441444
A = cbook.safe_masked_invalid(A, copy=True)
14451445
if not np.can_cast(A.dtype, float, "same_kind"):
@@ -1452,38 +1452,49 @@ def set_array(self, A):
14521452
raise TypeError(f"Image data of dtype {A.dtype} cannot be "
14531453
f"converted to a sequence of floats")
14541454
self._A = A
1455-
self.mapper.autoscale_None(A)
1455+
self.colorizer.autoscale_None(A)
1456+
1457+
def get_array(self):
1458+
"""
1459+
Return the array of values, that are mapped to colors.
1460+
1461+
The base class `.VectorMappable` does not make any assumptions on
1462+
the dimensionality and shape of the array.
1463+
"""
1464+
return self._A
14561465

14571466
@property
1458-
def mapper(self):
1459-
return self._mapper
1467+
def colorizer(self):
1468+
return self._colorizer
14601469

1461-
@mapper.setter
1462-
def mapper(self, mapper):
1463-
self._set_mapper(mapper)
1470+
@colorizer.setter
1471+
def colorizer(self, colorizer):
1472+
self._set_colorizer(colorizer)
14641473

1465-
def _set_mapper(self, mapper):
1466-
if isinstance(mapper, cm.Mapper):
1474+
def _set_colorizer(self, colorizer):
1475+
if isinstance(colorizer, cm.Colorizer):
14671476
if self._A is not None:
1468-
if not mapper.n_variates == self.mapper.n_variates:
1469-
raise ValueError('The new Mapper object must have the same'
1477+
if not colorizer.cmap.n_variates == self.colorizer.cmap.n_variates:
1478+
raise ValueError('The new Colorizer object must have the same'
14701479
' number of variates as the existing data.')
14711480
else:
1472-
self.mapper.callbacks.disconnect(self._id_mapper)
1473-
self._mapper = mapper
1474-
self._id_mapper = mapper.callbacks.connect('changed', self.changed)
1481+
self.colorizer.callbacks.disconnect(self._id_colorizer)
1482+
self._colorizer = colorizer
1483+
self._id_colorizer = colorizer.callbacks.connect('changed',
1484+
self.changed)
14751485
self.changed()
14761486
else:
1477-
raise ValueError('Only a Mapper object can be set to mapper.')
1487+
raise ValueError('Only a Colorizer object can be set to colorizer.')
14781488

1479-
def get_array(self):
1489+
def _get_colorizer(self):
14801490
"""
1481-
Return the array of values, that are mapped to colors.
1491+
Function to get the colorizer.
1492+
Useful in edge cases where you want a standalone variable with the colorizer,
1493+
but also want the colorizer to update if the colorizer on the artist changes.
14821494
1483-
The base class `.VectorMappable` does not make any assumptions on
1484-
the dimensionality and shape of the array.
1495+
used in `contour.ContourLabeler.label_colorizer`
14851496
"""
1486-
return self._A
1497+
return self._colorizer
14871498

14881499
def changed(self):
14891500
"""
@@ -1503,7 +1514,7 @@ def format_cursor_data(self, data):
15031514
--------
15041515
get_cursor_data
15051516
"""
1506-
return self.mapper._format_cursor_data(data)
1517+
return self.colorizer._format_cursor_data(data)
15071518

15081519

15091520
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

@@ -5963,7 +5979,7 @@ def imshow(self, X, cmap=None, norm=None, *, aspect=None,
59635979
if im.get_clip_path() is None:
59645980
# image does not already have clipping set, clip to Axes patch
59655981
im.set_clip_path(self.patch)
5966-
im._scale_norm(norm, vmin, vmax)
5982+
im.colorizer._scale_norm(norm, vmin, vmax, im.get_array())
59675983
im.set_url(url)
59685984

59695985
# update ax.dataLim, and, if autoscaling, set viewLim
@@ -6287,7 +6303,7 @@ def pcolor(self, *args, shading=None, alpha=None, norm=None, cmap=None,
62876303

62886304
collection = mcoll.PolyQuadMesh(
62896305
coords, array=C, cmap=cmap, norm=norm, alpha=alpha, **kwargs)
6290-
collection._scale_norm(norm, vmin, vmax)
6306+
collection.colorizer._scale_norm(norm, vmin, vmax, collection.get_array())
62916307

62926308
# Transform from native to data coordinates?
62936309
t = collection._transform
@@ -6522,7 +6538,7 @@ def pcolormesh(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
65226538
collection = mcoll.QuadMesh(
65236539
coords, antialiased=antialiased, shading=shading,
65246540
array=C, cmap=cmap, norm=norm, alpha=alpha, **kwargs)
6525-
collection._scale_norm(norm, vmin, vmax)
6541+
collection.colorizer._scale_norm(norm, vmin, vmax, collection.get_array())
65266542

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

@@ -6722,7 +6738,7 @@ def pcolorfast(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
67226738
ret = im
67236739

67246740
if np.ndim(C) == 2: # C.ndim == 3 is RGB(A) so doesn't need scaling.
6725-
ret._scale_norm(norm, vmin, vmax)
6741+
ret.colorizer._scale_norm(norm, vmin, vmax, C)
67266742

67276743
if ret.get_clip_path() is None:
67286744
# 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.