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
@@ -5954,7 +5970,7 @@ def imshow(self, X, cmap=None, norm=None, *, aspect=None,
5954
5970
if im .get_clip_path () is None :
5955
5971
# image does not already have clipping set, clip to Axes patch
5956
5972
im .set_clip_path (self .patch )
5957
- im ._scale_norm (norm , vmin , vmax )
5973
+ im .colorizer . _scale_norm (norm , vmin , vmax , im . get_array () )
5958
5974
im .set_url (url )
5959
5975
5960
5976
# update ax.dataLim, and, if autoscaling, set viewLim
@@ -6278,7 +6294,7 @@ def pcolor(self, *args, shading=None, alpha=None, norm=None, cmap=None,
6278
6294
6279
6295
collection = mcoll .PolyQuadMesh (
6280
6296
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 () )
6282
6298
6283
6299
# Transform from native to data coordinates?
6284
6300
t = collection ._transform
@@ -6513,7 +6529,7 @@ def pcolormesh(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
6513
6529
collection = mcoll .QuadMesh (
6514
6530
coords , antialiased = antialiased , shading = shading ,
6515
6531
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 () )
6517
6533
6518
6534
coords = coords .reshape (- 1 , 2 ) # flatten the grid structure; keep x, y
6519
6535
@@ -6713,7 +6729,7 @@ def pcolorfast(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
6713
6729
ret = im
6714
6730
6715
6731
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 )
6717
6733
6718
6734
if ret .get_clip_path () is None :
6719
6735
# image does not already have clipping set, clip to Axes patch
0 commit comments