@@ -337,7 +337,7 @@ def __init__(self, norm=None, cmap=None):
337
337
The colormap used to map normalized data values to RGBA colors.
338
338
"""
339
339
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.
341
341
self .set_norm (norm ) # The Normalize instance of this ScalarMappable.
342
342
self .cmap = None # So that the setter knows we're initializing.
343
343
self .set_cmap (cmap ) # The Colormap instance of this ScalarMappable.
@@ -496,6 +496,8 @@ def set_clim(self, vmin=None, vmax=None):
496
496
497
497
.. ACCEPTS: (vmin: float, vmax: float)
498
498
"""
499
+ # If the norm's limits are updated self.changed() will be called
500
+ # through the callbacks attached to the norm
499
501
if vmax is None :
500
502
try :
501
503
vmin , vmax = vmin
@@ -505,7 +507,6 @@ def set_clim(self, vmin=None, vmax=None):
505
507
self .norm .vmin = colors ._sanitize_extrema (vmin )
506
508
if vmax is not None :
507
509
self .norm .vmax = colors ._sanitize_extrema (vmax )
508
- self .changed ()
509
510
510
511
def get_alpha (self ):
511
512
"""
@@ -531,6 +532,30 @@ def set_cmap(self, cmap):
531
532
if not in_init :
532
533
self .changed () # Things are not set up properly yet.
533
534
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
+
534
559
def set_norm (self , norm ):
535
560
"""
536
561
Set the normalization instance.
@@ -545,13 +570,7 @@ def set_norm(self, norm):
545
570
the norm of the mappable will reset the norm, locator, and formatters
546
571
on the colorbar to default.
547
572
"""
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 ()
552
573
self .norm = norm
553
- if not in_init :
554
- self .changed () # Things are not set up properly yet.
555
574
556
575
def autoscale (self ):
557
576
"""
@@ -560,8 +579,9 @@ def autoscale(self):
560
579
"""
561
580
if self ._A is None :
562
581
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
563
584
self .norm .autoscale (self ._A )
564
- self .changed ()
565
585
566
586
def autoscale_None (self ):
567
587
"""
@@ -570,8 +590,9 @@ def autoscale_None(self):
570
590
"""
571
591
if self ._A is None :
572
592
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
573
595
self .norm .autoscale_None (self ._A )
574
- self .changed ()
575
596
576
597
def changed (self ):
577
598
"""
0 commit comments