@@ -337,7 +337,7 @@ def __init__(self, norm=None, cmap=None):
337337 The colormap used to map normalized data values to RGBA colors.
338338 """
339339 self ._A = None
340- self .norm = None # So that the setter knows we're initializing.
340+ self ._norm = None # So that the setter knows we're initializing.
341341 self .set_norm (norm ) # The Normalize instance of this ScalarMappable.
342342 self .cmap = None # So that the setter knows we're initializing.
343343 self .set_cmap (cmap ) # The Colormap instance of this ScalarMappable.
@@ -496,6 +496,8 @@ def set_clim(self, vmin=None, vmax=None):
496496
497497 .. ACCEPTS: (vmin: float, vmax: float)
498498 """
499+ # If the norm's limits are updated self.changed() will be called
500+ # through the callbacks attached to the norm
499501 if vmax is None :
500502 try :
501503 vmin , vmax = vmin
@@ -505,7 +507,6 @@ def set_clim(self, vmin=None, vmax=None):
505507 self .norm .vmin = colors ._sanitize_extrema (vmin )
506508 if vmax is not None :
507509 self .norm .vmax = colors ._sanitize_extrema (vmax )
508- self .changed ()
509510
510511 def get_alpha (self ):
511512 """
@@ -531,6 +532,30 @@ def set_cmap(self, cmap):
531532 if not in_init :
532533 self .changed () # Things are not set up properly yet.
533534
535+ @property
536+ def norm (self ):
537+ return self ._norm
538+
539+ @norm .setter
540+ def norm (self , norm ):
541+ _api .check_isinstance ((colors .Normalize , None ), norm = norm )
542+ if norm is None :
543+ norm = colors .Normalize ()
544+
545+ if norm is self .norm :
546+ # We aren't updating anything
547+ return
548+
549+ in_init = self .norm is None
550+ # Remove the current callback and connect to the new one
551+ if not in_init :
552+ self .norm .callbacks .disconnect (self ._id_norm )
553+ self ._norm = norm
554+ self ._id_norm = self .norm .callbacks .connect ('changed' ,
555+ self .changed )
556+ if not in_init :
557+ self .changed ()
558+
534559 def set_norm (self , norm ):
535560 """
536561 Set the normalization instance.
@@ -545,13 +570,7 @@ def set_norm(self, norm):
545570 the norm of the mappable will reset the norm, locator, and formatters
546571 on the colorbar to default.
547572 """
548- _api .check_isinstance ((colors .Normalize , None ), norm = norm )
549- in_init = self .norm is None
550- if norm is None :
551- norm = colors .Normalize ()
552573 self .norm = norm
553- if not in_init :
554- self .changed () # Things are not set up properly yet.
555574
556575 def autoscale (self ):
557576 """
@@ -560,8 +579,9 @@ def autoscale(self):
560579 """
561580 if self ._A is None :
562581 raise TypeError ('You must first set_array for mappable' )
582+ # If the norm's limits are updated self.changed() will be called
583+ # through the callbacks attached to the norm
563584 self .norm .autoscale (self ._A )
564- self .changed ()
565585
566586 def autoscale_None (self ):
567587 """
@@ -570,8 +590,9 @@ def autoscale_None(self):
570590 """
571591 if self ._A is None :
572592 raise TypeError ('You must first set_array for mappable' )
593+ # If the norm's limits are updated self.changed() will be called
594+ # through the callbacks attached to the norm
573595 self .norm .autoscale_None (self ._A )
574- self .changed ()
575596
576597 def changed (self ):
577598 """
0 commit comments