@@ -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
"""
@@ -436,6 +433,30 @@ def set_cmap(self, cmap):
436
433
if not in_init :
437
434
self .changed () # Things are not set up properly yet.
438
435
436
+ @property
437
+ def norm (self ):
438
+ return self ._norm
439
+
440
+ @norm .setter
441
+ def norm (self , norm ):
442
+ _api .check_isinstance ((colors .Normalize , None ), norm = norm )
443
+ if norm is None :
444
+ norm = colors .Normalize ()
445
+
446
+ if norm is self .norm :
447
+ # We aren't updating anything
448
+ return
449
+
450
+ in_init = self .norm is None
451
+ # Remove the current callback and connect to the new one
452
+ if not in_init :
453
+ self .norm .callbacksNorm .disconnect (self ._id_norm )
454
+ self ._norm = norm
455
+ self ._id_norm = self .norm .callbacksNorm .connect ('changed' ,
456
+ self .changed )
457
+ if not in_init :
458
+ self .changed ()
459
+
439
460
def set_norm (self , norm ):
440
461
"""
441
462
Set the normalization instance.
@@ -450,13 +471,7 @@ def set_norm(self, norm):
450
471
the norm of the mappable will reset the norm, locator, and formatters
451
472
on the colorbar to default.
452
473
"""
453
- _api .check_isinstance ((colors .Normalize , None ), norm = norm )
454
- in_init = self .norm is None
455
- if norm is None :
456
- norm = colors .Normalize ()
457
474
self .norm = norm
458
- if not in_init :
459
- self .changed () # Things are not set up properly yet.
460
475
461
476
def autoscale (self ):
462
477
"""
0 commit comments