42
42
of the colorbar, as that also determines the *orientation*; passing
43
43
incompatible values for *location* and *orientation* raises an exception.
44
44
45
+ ticklocation : {'auto', 'left', 'right', 'top', 'bottom'}
46
+ The location of the colorbar ticks. The *ticklocation* location value must
47
+ match *orientation*. For example, a horizontal colorbar can only have ticks
48
+ at the top or the bottom.
49
+
45
50
fraction : float, default: 0.15
46
51
Fraction of original axes to use for colorbar.
47
52
@@ -321,13 +326,17 @@ class Colorbar:
321
326
alpha : float
322
327
The colorbar transparency between 0 (transparent) and 1 (opaque).
323
328
324
- orientation : {'vertical', 'horizontal'}
329
+ orientation : None or {'vertical', 'horizontal'}
330
+ If None, use the value determined by *location*. If both
331
+ *orientation* and *location* are None, 'vertical'.
325
332
326
333
ticklocation : {'auto', 'left', 'right', 'top', 'bottom'}
327
334
328
335
drawedges : bool
329
336
330
337
filled : bool
338
+
339
+ location : None or {'left', 'right', 'top', 'bottom'}
331
340
%s
332
341
"""
333
342
@@ -339,7 +348,7 @@ def __init__(self, ax, mappable=None, *, cmap=None,
339
348
alpha = None ,
340
349
values = None ,
341
350
boundaries = None ,
342
- orientation = 'vertical' ,
351
+ orientation = None ,
343
352
ticklocation = 'auto' ,
344
353
extend = None ,
345
354
spacing = 'uniform' , # uniform or proportional
@@ -350,6 +359,7 @@ def __init__(self, ax, mappable=None, *, cmap=None,
350
359
extendfrac = None ,
351
360
extendrect = False ,
352
361
label = '' ,
362
+ location = None ,
353
363
):
354
364
355
365
if mappable is None :
@@ -380,14 +390,26 @@ def __init__(self, ax, mappable=None, *, cmap=None,
380
390
mappable .colorbar_cid = mappable .callbacks .connect (
381
391
'changed' , self .update_normal )
382
392
393
+ location_orientation = _api .check_getitem (
394
+ {None : None , "left" : "vertical" , "right" : "vertical" ,
395
+ "top" : "horizontal" , "bottom" : "horizontal" },
396
+ location = location )
397
+
383
398
_api .check_in_list (
384
- ['vertical' , 'horizontal' ], orientation = orientation )
399
+ [None , 'vertical' , 'horizontal' ], orientation = orientation )
385
400
_api .check_in_list (
386
401
['auto' , 'left' , 'right' , 'top' , 'bottom' ],
387
402
ticklocation = ticklocation )
388
403
_api .check_in_list (
389
404
['uniform' , 'proportional' ], spacing = spacing )
390
405
406
+ if location_orientation is not None and orientation is not None :
407
+ if location_orientation != orientation :
408
+ raise TypeError (
409
+ "location and orientation are mutually exclusive" )
410
+ else :
411
+ orientation = orientation or location_orientation or "vertical"
412
+
391
413
self .ax = ax
392
414
self .ax ._axes_locator = _ColorbarAxesLocator (self )
393
415
@@ -445,7 +467,11 @@ def __init__(self, ax, mappable=None, *, cmap=None,
445
467
self .__scale = None # linear, log10 for now. Hopefully more?
446
468
447
469
if ticklocation == 'auto' :
448
- ticklocation = 'bottom' if orientation == 'horizontal' else 'right'
470
+ if location is None :
471
+ ticklocation = (
472
+ 'bottom' if orientation == 'horizontal' else 'right' )
473
+ else :
474
+ ticklocation = location
449
475
self .ticklocation = ticklocation
450
476
451
477
self .set_label (label )
0 commit comments