@@ -387,30 +387,26 @@ def __init__(self, ax, cmap=None,
387
387
self .outline = None
388
388
self .patch = None
389
389
self .dividers = None
390
+ self .locator = None
391
+ self .formatter = None
390
392
self ._manual_tick_data_values = None
391
393
392
394
if ticklocation == 'auto' :
393
395
ticklocation = 'bottom' if orientation == 'horizontal' else 'right'
394
396
self .ticklocation = ticklocation
395
397
396
398
self .set_label (label )
399
+ self ._reset_locator_formatter_scale ()
400
+
397
401
if np .iterable (ticks ):
398
402
self .locator = ticker .FixedLocator (ticks , nbins = len (ticks ))
399
403
else :
400
404
self .locator = ticks # Handle default in _ticker()
401
- if format is None :
402
- if isinstance (self .norm , colors .LogNorm ):
403
- self .formatter = ticker .LogFormatterSciNotation ()
404
- elif isinstance (self .norm , colors .SymLogNorm ):
405
- self .formatter = ticker .LogFormatterSciNotation (
406
- linthresh = self .norm .linthresh )
407
- else :
408
- self .formatter = ticker .ScalarFormatter ()
409
- elif isinstance (format , str ):
405
+
406
+ if isinstance (format , str ):
410
407
self .formatter = ticker .FormatStrFormatter (format )
411
408
else :
412
- self .formatter = format # Assume it is a Formatter
413
- # The rest is in a method so we can recalculate when clim changes.
409
+ self .formatter = format # Assume it is a Formatter or None
414
410
self .draw_all ()
415
411
416
412
def _extend_lower (self ):
@@ -432,7 +428,6 @@ def draw_all(self):
432
428
Calculate any free parameters based on the current cmap and norm,
433
429
and do all the drawing.
434
430
'''
435
-
436
431
# sets self._boundaries and self._values in real data units.
437
432
# takes into account extend values:
438
433
self ._process_values ()
@@ -449,14 +444,14 @@ def draw_all(self):
449
444
if self .filled :
450
445
self ._add_solids (X , Y , C )
451
446
447
+ def set_norm (self , norm ):
448
+ """
449
+ set the norm of the mappable associated with this colorbar.
450
+ """
451
+ self .mappable .set_norm (norm )
452
+
452
453
def config_axis (self ):
453
454
ax = self .ax
454
- if (isinstance (self .norm , colors .LogNorm )
455
- and self ._use_auto_colorbar_locator ()):
456
- # *both* axes are made log so that determining the
457
- # mid point is easier.
458
- ax .set_xscale ('log' )
459
- ax .set_yscale ('log' )
460
455
461
456
if self .orientation == 'vertical' :
462
457
long_axis , short_axis = ax .yaxis , ax .xaxis
@@ -504,6 +499,20 @@ def _get_ticker_locator_formatter(self):
504
499
else :
505
500
b = self ._boundaries [self ._inside ]
506
501
locator = ticker .FixedLocator (b , nbins = 10 )
502
+
503
+ if formatter is None :
504
+ if isinstance (self .norm , colors .LogNorm ):
505
+ formatter = ticker .LogFormatterSciNotation ()
506
+ elif isinstance (self .norm , colors .SymLogNorm ):
507
+ formatter = ticker .LogFormatterSciNotation (
508
+ linthresh = self .norm .linthresh )
509
+ else :
510
+ formatter = ticker .ScalarFormatter ()
511
+ else :
512
+ formatter = self .formatter
513
+
514
+ self .locator = locator
515
+ self .formatter = formatter
507
516
_log .debug ('locator: %r' , locator )
508
517
return locator , formatter
509
518
@@ -517,6 +526,24 @@ def _use_auto_colorbar_locator(self):
517
526
and ((type (self .norm ) == colors .Normalize )
518
527
or (type (self .norm ) == colors .LogNorm )))
519
528
529
+ def _reset_locator_formatter_scale (self ):
530
+ """
531
+ Reset the locator et al to defaults. Any user-hardcoded changes
532
+ need to be re-entered if this gets called (either at init, or when
533
+ the mappable normal gets changed: Colorbar.update_normal)
534
+ """
535
+ self .locator = None
536
+ self .formatter = None
537
+ if (isinstance (self .norm , colors .LogNorm )
538
+ and self ._use_auto_colorbar_locator ()):
539
+ # *both* axes are made log so that determining the
540
+ # mid point is easier.
541
+ self .ax .set_xscale ('log' )
542
+ self .ax .set_yscale ('log' )
543
+ else :
544
+ self .ax .set_xscale ('linear' )
545
+ self .ax .set_yscale ('linear' )
546
+
520
547
def update_ticks (self ):
521
548
"""
522
549
Force the update of the ticks and ticklabels. This must be
@@ -526,7 +553,6 @@ def update_ticks(self):
526
553
# get the locator and formatter. Defaults to
527
554
# self.locator if not None..
528
555
locator , formatter = self ._get_ticker_locator_formatter ()
529
-
530
556
if self .orientation == 'vertical' :
531
557
long_axis , short_axis = ax .yaxis , ax .xaxis
532
558
else :
@@ -1082,7 +1108,6 @@ def __init__(self, ax, mappable, **kw):
1082
1108
kw ['boundaries' ] = CS ._levels
1083
1109
kw ['values' ] = CS .cvalues
1084
1110
kw ['extend' ] = CS .extend
1085
- #kw['ticks'] = CS._levels
1086
1111
kw .setdefault ('ticks' , ticker .FixedLocator (CS .levels , nbins = 10 ))
1087
1112
kw ['filled' ] = CS .filled
1088
1113
ColorbarBase .__init__ (self , ax , ** kw )
@@ -1105,6 +1130,7 @@ def on_mappable_changed(self, mappable):
1105
1130
by :func:`colorbar_factory` and should not be called manually.
1106
1131
1107
1132
"""
1133
+ _log .debug ('colorbar mappable changed' )
1108
1134
self .set_cmap (mappable .get_cmap ())
1109
1135
self .set_clim (mappable .get_clim ())
1110
1136
self .update_normal (mappable )
@@ -1136,9 +1162,20 @@ def update_normal(self, mappable):
1136
1162
Update solid patches, lines, etc.
1137
1163
1138
1164
Unlike `.update_bruteforce`, this does not clear the axes. This is
1139
- meant to be called when the image or contour plot to which this
1140
- colorbar belongs changes.
1165
+ meant to be called when the norm of the image or contour plot to which
1166
+ this colorbar belongs changes.
1167
+
1168
+ This resets the locator and formatter for the axis, so if these
1169
+ have been customized, they will need to be customized again.
1141
1170
"""
1171
+
1172
+ _log .debug ('colorbar update normal' )
1173
+ self .mappable = mappable
1174
+ self .set_alpha (mappable .get_alpha ())
1175
+ self .cmap = mappable .cmap
1176
+ self .norm = mappable .norm
1177
+ self ._reset_locator_formatter_scale ()
1178
+
1142
1179
self .draw_all ()
1143
1180
if isinstance (self .mappable , contour .ContourSet ):
1144
1181
CS = self .mappable
@@ -1160,15 +1197,16 @@ def update_bruteforce(self, mappable):
1160
1197
# properties have been changed by methods other than the
1161
1198
# colorbar methods, those changes will be lost.
1162
1199
self .ax .cla ()
1200
+ self .locator = None
1201
+ self .formatter = None
1202
+
1163
1203
# clearing the axes will delete outline, patch, solids, and lines:
1164
1204
self .outline = None
1165
1205
self .patch = None
1166
1206
self .solids = None
1167
1207
self .lines = list ()
1168
1208
self .dividers = None
1169
- self .set_alpha (mappable .get_alpha ())
1170
- self .cmap = mappable .cmap
1171
- self .norm = mappable .norm
1209
+ self .update_normal (mappable )
1172
1210
self .draw_all ()
1173
1211
if isinstance (self .mappable , contour .ContourSet ):
1174
1212
CS = self .mappable
0 commit comments