@@ -257,16 +257,13 @@ def __init__(self, norm=None, cmap=None):
257257 The colormap used to map normalized data values to RGBA colors.
258258 """
259259 self ._A = None
260- self .norm = None # So that the setter knows we're initializing.
260+ self ._norm = None # So that the setter knows we're initializing.
261261 self .set_norm (norm ) # The Normalize instance of this ScalarMappable.
262262 self .cmap = None # So that the setter knows we're initializing.
263263 self .set_cmap (cmap ) # The Colormap instance of this ScalarMappable.
264264 #: The last colorbar associated with this ScalarMappable. May be None.
265265 self .colorbar = None
266266 self .callbacksSM = cbook .CallbackRegistry ()
267- # Connect to the Norm's callback
268- self ._id_norm = self .norm .callbacksNorm .connect ('changed' ,
269- self .changed )
270267
271268 def _scale_norm (self , norm , vmin , vmax ):
272269 """
@@ -454,6 +451,30 @@ def set_cmap(self, cmap):
454451 if not in_init :
455452 self .changed () # Things are not set up properly yet.
456453
454+ @property
455+ def norm (self ):
456+ return self ._norm
457+
458+ @norm .setter
459+ def norm (self , norm ):
460+ _api .check_isinstance ((colors .Normalize , None ), norm = norm )
461+ if norm is None :
462+ norm = colors .Normalize ()
463+
464+ if norm is self .norm :
465+ # We aren't updating anything
466+ return
467+
468+ in_init = self .norm is None
469+ # Remove the current callback and connect to the new one
470+ if not in_init :
471+ self .norm .callbacksNorm .disconnect (self ._id_norm )
472+ self ._norm = norm
473+ self ._id_norm = self .norm .callbacksNorm .connect ('changed' ,
474+ self .changed )
475+ if not in_init :
476+ self .changed ()
477+
457478 def set_norm (self , norm ):
458479 """
459480 Set the normalization instance.
@@ -468,13 +489,7 @@ def set_norm(self, norm):
468489 the norm of the mappable will reset the norm, locator, and formatters
469490 on the colorbar to default.
470491 """
471- _api .check_isinstance ((colors .Normalize , None ), norm = norm )
472- in_init = self .norm is None
473- if norm is None :
474- norm = colors .Normalize ()
475492 self .norm = norm
476- if not in_init :
477- self .changed () # Things are not set up properly yet.
478493
479494 def autoscale (self ):
480495 """
0 commit comments