Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit32e0256

Browse 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 ColorizerMapper → ColorizerScalarMappableShim → ColorizerShimColorableArtist → ColorizingArtistalso removed all internal calls using the ColorizerShim api
1 parent7f6fe56 commit32e0256

File tree

11 files changed

+277
-207
lines changed

11 files changed

+277
-207
lines changed

‎lib/matplotlib/artist.py

Lines 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-
returnself.mapper._format_cursor_data(data)
1357+
returnself.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-
classColorableArtist(Artist):
1400+
classColorizingArtist(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-
ifisinstance(norm,cm.Mapper):
1420-
self._mapper=norm
1419+
ifisinstance(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
defset_array(self,A):
@@ -1439,7 +1439,7 @@ def set_array(self, A):
14391439
ifAisNone:
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
ifnotnp.can_cast(A.dtype,float,"same_kind"):
@@ -1452,38 +1452,49 @@ def set_array(self, A):
14521452
raiseTypeError(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+
defget_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+
returnself._A
14561465

14571466
@property
1458-
defmapper(self):
1459-
returnself._mapper
1467+
defcolorizer(self):
1468+
returnself._colorizer
14601469

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

1465-
def_set_mapper(self,mapper):
1466-
ifisinstance(mapper,cm.Mapper):
1474+
def_set_colorizer(self,colorizer):
1475+
ifisinstance(colorizer,cm.Colorizer):
14671476
ifself._AisnotNone:
1468-
ifnotmapper.n_variates==self.mapper.n_variates:
1469-
raiseValueError('The newMapper object must have the same'
1477+
ifnotcolorizer.cmap.n_variates==self.colorizer.cmap.n_variates:
1478+
raiseValueError('The newColorizer 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-
raiseValueError('Only aMapper object can be set tomapper.')
1487+
raiseValueError('Only aColorizer object can be set tocolorizer.')
14781488

1479-
defget_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-
returnself._A
1497+
returnself._colorizer
14871498

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

15081519

15091520
def_get_tightbbox_for_layout_only(obj,*args,**kwargs):

‎lib/matplotlib/axes/_axes.py

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
frommatplotlibimport_api,_docstring,_preprocess_data
3535
frommatplotlib.axes._baseimport (
3636
_AxesBase,_TransformedBoundsLocator,_process_plot_format)
37-
frommatplotlib.cmimport_ensure_cmap,_ensure_multivariate_params
37+
frommatplotlib.cmimport_ensure_cmap,_ensure_multivariate_params,Colorizer
3838
frommatplotlib.axes._secondary_axesimportSecondaryAxis
3939
frommatplotlib.containerimportBarContainer,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
ifcolorsisNone:
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
ifcbook._str_equal(bins,'log'):
52795271
ifnormisnotNone:
@@ -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+
ifmarginals:
5290+
ifvminisNone \
5291+
andvmaxisNone \
5292+
andnotisinstance(norm,mcolors.Normalize)\
5293+
andnotisinstance(norm,Colorizer)\
5294+
and'clim'notinkwargs:
5295+
marginals_share_colorizer=False
5296+
else:
5297+
marginals_share_colorizer=True
5298+
52875299
ifbinsisnotNone:
52885300
ifnotnp.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+
ifmarginals_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-
defon_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+
ifnotmarginals_share_colorizer:
5379+
defon_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
returncollection
53705386

@@ -5963,7 +5979,7 @@ def imshow(self, X, cmap=None, norm=None, *, aspect=None,
59635979
ifim.get_clip_path()isNone:
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
ifnp.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
ifret.get_clip_path()isNone:
67286744
# image does not already have clipping set, clip to Axes patch

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

Lines 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
forlabel,mappableinlabeled_mappables:
150-
cmap=mappable.get_cmap()
150+
cmap=mappable.colorizer.cmap
151151
ifisinstance(cmap,mcolors.Colormap):
152152
cmaps= [(cmap,name)forname,cmapinsorted(cm._colormaps.items())]
153153
cvals=cm._colormaps.values()
154154
elifisinstance(cmap,mcolors.BivarColormap):
155155
cmaps= [(cmap,name)forname,cmapinsorted(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)forname,cmap
159159
insorted(cm._multivar_colormaps.items())]
160160
cvals=cm._multivar_colormaps.values()
161161
ifcmapnotincvals:
162162
cmaps= [(cmap,cmap.name),*cmaps]
163-
low,high=mappable.mapper.get_clim()
163+
low,high=mappable.colorizer.get_clim()
164164
iflen(low)==1:
165165
low=low[0]
166166
high=high[0]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp