3434from matplotlib import _api , _docstring , _preprocess_data
3535from 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
3838from matplotlib .axes ._secondary_axes import SecondaryAxis
3939from 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_arra
ACE
y () )
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+
ACE
collection .callbacks .connect ('changed' , on_changed )
53685384
53695385 return collection
100F2
div>
53705386
@@ -5954,7 +5970,7 @@ def imshow(self, X, cmap=None, norm=None, *, aspect=None,
59545970 if im .get_clip_path () is None :
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 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 )
67176733
67186734 if ret .get_clip_path () is None :
67196735 # image does not already have clipping set, clip to Axes patch
0 commit comments