34
34
from matplotlib import _api , _docstring , _preprocess_data
35
35
from matplotlib .axes ._base import (
36
36
_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
38
38
from matplotlib .axes ._secondary_axes import SecondaryAxis
39
39
from matplotlib .container import BarContainer , ErrorbarContainer , StemContainer
40
40
@@ -4940,9 +4940,9 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
4940
4940
collection .set_transform (mtransforms .IdentityTransform ())
4941
4941
if colors is None :
4942
4942
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 () )
4946
4946
else :
4947
4947
extra_kwargs = {
4948
4948
'cmap' : cmap , 'norm' : norm , 'vmin' : vmin , 'vmax' : vmax
@@ -5266,14 +5266,6 @@ def reduce_C_function(C: array) -> float
5266
5266
else :
5267
5267
polygons = [polygon ]
5268
5268
5269
- collection = mcoll .PolyCollection (
5270
- polygons ,
5271
- edgecolors = edgecolors ,
5272
- linewidths = linewidths ,
5273
- offsets = offsets ,
5274
- offset_transform = mtransforms .AffineDeltaTransform (self .transData )
5275
- )
5276
-
5277
5269
# Set normalizer if bins is 'log'
5278
5270
if cbook ._str_equal (bins , 'log' ):
5279
5271
if norm is not None :
@@ -5284,6 +5276,26 @@ def reduce_C_function(C: array) -> float
5284
5276
vmin = vmax = None
5285
5277
bins = None
5286
5278
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
+
5287
5299
if bins is not None :
5288
5300
if not np .iterable (bins ):
5289
5301
minimum , maximum = min (accum ), max (accum )
@@ -5293,16 +5305,16 @@ def reduce_C_function(C: array) -> float
5293
5305
accum = bins .searchsorted (accum )
5294
5306
5295
5307
collection .set_array (accum )
5296
- collection .set_cmap (cmap )
5297
- collection .set_norm (norm )
5298
5308
collection .set_alpha (alpha )
5299
5309
collection ._internal_update (kwargs )
5300
- collection ._scale_norm (norm , vmin , vmax )
5310
+ collection .colorizer . _scale_norm (norm , vmin , vmax , collection . get_array () )
5301
5311
5312
+ '''
5302
5313
# autoscale the norm with current accum values if it hasn't been set
5303
5314
if norm is not None:
5304
5315
if collection.norm.vmin is None and collection.norm.vmax is None:
5305
5316
collection.norm.autoscale()
5317
+ '''
5306
5318
5307
5319
corners = ((xmin , ymin ), (xmax , ymax ))
5308
5320
self .update_datalim (corners )
@@ -5347,24 +5359,28 @@ def reduce_C_function(C: array) -> float
5347
5359
values = values [mask ]
5348
5360
5349
5361
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
5352
5371
bar .set_array (values )
5353
- bar .set_cmap (cmap )
5354
- bar .set_norm (norm )
5355
5372
bar .set_alpha (alpha )
5356
5373
bar ._internal_update (kwargs )
5357
5374
bars .append (self .add_collection (bar , autolim = False ))
5358
5375
5359
5376
collection .hbar , collection .vbar = bars
5360
5377
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 ())
5366
5382
5367
- collection .callbacks .connect ('changed' , on_changed )
5383
+ collection .callbacks .connect ('changed' , on_changed )
5368
5384
5369
5385
return collection
5370
5386
@@ -5963,7 +5979,7 @@ def imshow(self, X, cmap=None, norm=None, *, aspect=None,
5963
5979
if im .get_clip_path () is None :
5964
5980
# image does not already have clipping set, clip to Axes patch
5965
5981
im .set_clip_path (self .patch )
5966
- im ._scale_norm (norm , vmin , vmax )
5982
+ im .colorizer . _scale_norm (norm , vmin , vmax , im . get_array () )
5967
5983
im .set_url (url )
5968
5984
5969
5985
# update ax.dataLim, and, if autoscaling, set viewLim
@@ -6287,7 +6303,7 @@ def pcolor(self, *args, shading=None, alpha=None, norm=None, cmap=None,
6287
6303
6288
6304
collection = mcoll .PolyQuadMesh (
6289
6305
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 () )
6291
6307
6292
6308
# Transform from native to data coordinates?
6293
6309
t = collection ._transform
@@ -6522,7 +6538,7 @@ def pcolormesh(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
6522
6538
collection = mcoll .QuadMesh (
6523
6539
coords , antialiased = antialiased , shading = shading ,
6524
6540
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 () )
6526
6542
6527
6543
coords = coords .reshape (- 1 , 2 ) # flatten the grid structure; keep x, y
6528
6544
@@ -6722,7 +6738,7 @@ def pcolorfast(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
6722
6738
ret = im
6723
6739
6724
6740
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 )
6726
6742
6727
6743
if ret .get_clip_path () is None :
6728
6744
# image does not already have clipping set, clip to Axes patch
0 commit comments