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

Commitf9b2bf0

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 parente6a7c9b commitf9b2bf0

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
@@ -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-
returnself.mapper._format_cursor_data(data)
1338+
returnself.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-
classColorableArtist(Artist):
1381+
classColorizingArtist(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-
ifisinstance(norm,cm.Mapper):
1401-
self._mapper=norm
1400+
ifisinstance(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
defset_array(self,A):
@@ -1420,7 +1420,7 @@ def set_array(self, A):
14201420
ifAisNone:
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
ifnotnp.can_cast(A.dtype,float,"same_kind"):
@@ -1433,38 +1433,49 @@ def set_array(self, A):
14331433
raiseTypeError(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+
defget_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+
returnself._A
14371446

14381447
@property
1439-
defmapper(self):
1440-
returnself._mapper
1448+
defcolorizer(self):
1449+
returnself._colorizer
14411450

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

1446-
def_set_mapper(self,mapper):
1447-
ifisinstance(mapper,cm.Mapper):
1455+
def_set_colorizer(self,colorizer):
1456+
ifisinstance(colorizer,cm.Colorizer):
14481457
ifself._AisnotNone:
1449-
ifnotmapper.n_variates==self.mapper.n_variates:
1450-
raiseValueError('The newMapper object must have the same'
1458+
ifnotcolorizer.cmap.n_variates==self.colorizer.cmap.n_variates:
1459+
raiseValueError('The newColorizer 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-
raiseValueError('Only aMapper object can be set tomapper.')
1468+
raiseValueError('Only aColorizer object can be set tocolorizer.')
14591469

1460-
defget_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-
returnself._A
1478+
returnself._colorizer
14681479

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

14891500

14901501
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

@@ -5954,7 +5970,7 @@ def imshow(self, X, cmap=None, norm=None, *, aspect=None,
59545970
ifim.get_clip_path()isNone:
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
ifnp.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
ifret.get_clip_path()isNone:
67196735
# 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