@@ -257,16 +257,13 @@ def __init__(self, norm=None, cmap=None):
257
257
The colormap used to map normalized data values to RGBA colors.
258
258
"""
259
259
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.
261
261
self .set_norm (norm ) # The Normalize instance of this ScalarMappable.
262
262
self .cmap = None # So that the setter knows we're initializing.
263
263
self .set_cmap (cmap ) # The Colormap instance of this ScalarMappable.
264
264
#: The last colorbar associated with this ScalarMappable. May be None.
265
265
self .colorbar = None
266
266
self .callbacksSM = cbook .CallbackRegistry ()
267
- # Connect to the Norm's callback
268
- self ._id_norm = self .norm .callbacksNorm .connect ('changed' ,
269
- self .changed )
270
267
271
268
def _scale_norm (self , norm , vmin , vmax ):
272
269
"""
@@ -454,6 +451,30 @@ def set_cmap(self, cmap):
454
451
if not in_init :
455
452
self .changed () # Things are not set up properly yet.
456
453
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
+
457
478
def set_norm (self , norm ):
458
479
"""
459
480
Set the normalization instance.
@@ -468,13 +489,7 @@ def set_norm(self, norm):
468
489
the norm of the mappable will reset the norm, locator, and formatters
469
490
on the colorbar to default.
470
491
"""
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 ()
475
492
self .norm = norm
476
- if not in_init :
477
- self .changed () # Things are not set up properly yet.
478
493
479
494
def autoscale (self ):
480
495
"""
0 commit comments