@@ -291,7 +291,7 @@ def __init__(self, ax, mappable=None, *, cmap=None,
291
291
drawedges = False ,
292
292
extendfrac = None ,
293
293
extendrect = False ,
294
- label = '' ,
294
+ label = None ,
295
295
location = None ,
296
296
):
297
297
@@ -370,6 +370,7 @@ def __init__(self, ax, mappable=None, *, cmap=None,
370
370
self .solids_patches = []
371
371
self .lines = []
372
372
373
+
373
374
for spine in self .ax .spines .values ():
374
375
spine .set_visible (False )
375
376
self .outline = self .ax .spines ['outline' ] = _ColorbarSpine (self .ax )
@@ -391,8 +392,10 @@ def __init__(self, ax, mappable=None, *, cmap=None,
391
392
orientation ) if location is None else location
392
393
self .ticklocation = ticklocation
393
394
394
- self .set_label (label )
395
+ if label is not None :
396
+ self .set_label (label )
395
397
self ._reset_locator_formatter_scale ()
398
+ self ._set_units_from_mappable ()
396
399
397
400
if np .iterable (ticks ):
398
401
self ._locator = ticker .FixedLocator (ticks , nbins = len (ticks ))
@@ -1331,6 +1334,27 @@ def drag_pan(self, button, key, x, y):
1331
1334
elif self .orientation == 'vertical' :
1332
1335
self .norm .vmin , self .norm .vmax = points [:, 1 ]
1333
1336
1337
+ def _set_units_from_mappable (self ):
1338
+ """
1339
+ Set the colorbar locator and formatter if the mappable has units.
1340
+ """
1341
+ self ._units = self .mappable ._units
1342
+ self ._converter = self .mappable ._converter
1343
+ if self ._converter is not None :
1344
+
1345
+ axis = self ._long_axis ()
1346
+ info = self ._converter .axisinfo (self ._units , axis )
1347
+
1348
+ if info is not None :
1349
+ if info .majloc is not None :
1350
+ self .locator = info .majloc
1351
+ if info .minloc is not None :
1352
+ self .minorlocator = info .minloc
1353
+ if info .majfmt is not None :
1354
+ self .formatter = info .majfmt
1355
+ if info .minfmt is not None :
1356
+ self .minorformatter = info .minfmt
1357
+
1334
1358
1335
1359
ColorbarBase = Colorbar # Backcompat API
1336
1360
0 commit comments