4242 of the colorbar, as that also determines the *orientation*; passing
4343 incompatible values for *location* and *orientation* raises an exception.
4444
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+
4550fraction : float, default: 0.15
4651 Fraction of original axes to use for colorbar.
4752
@@ -321,13 +326,17 @@ class Colorbar:
321326 alpha : float
322327 The colorbar transparency between 0 (transparent) and 1 (opaque).
323328
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'.
325332
326333 ticklocation : {'auto', 'left', 'right', 'top', 'bottom'}
327334
328335 drawedges : bool
329336
330337 filled : bool
338+
339+ location : None or {'left', 'right', 'top', 'bottom'}
331340 %s
332341 """
333342
@@ -339,7 +348,7 @@ def __init__(self, ax, mappable=None, *, cmap=None,
339348 alpha = None ,
340349 values = None ,
341350 boundaries = None ,
342- orientation = 'vertical' ,
351+ orientation = None ,
343352 ticklocation = 'auto' ,
344353 extend = None ,
345354 spacing = 'uniform' , # uniform or proportional
@@ -350,6 +359,7 @@ def __init__(self, ax, mappable=None, *, cmap=None,
350359 extendfrac = None ,
351360 extendrect = False ,
352361 label = '' ,
362+ location = None ,
353363 ):
354364
355365 if mappable is None :
@@ -380,14 +390,26 @@ def __init__(self, ax, mappable=None, *, cmap=None,
380390 mappable .colorbar_cid = mappable .callbacks .connect (
381391 'changed' , self .update_normal )
382392
393+ location_orientation = _api .check_getitem (
394+ {None : None , "left" : "vertical" , "right" : "vertical" ,
395+ "top" : "horizontal" , "bottom" : "horizontal" },
396+ location = location )
397+
383398 _api .check_in_list (
384- ['vertical' , 'horizontal' ], orientation = orientation )
399+ [None , 'vertical' , 'horizontal' ], orientation = orientation )
385400 _api .check_in_list (
386401 ['auto' , 'left' , 'right' , 'top' , 'bottom' ],
387402 ticklocation = ticklocation )
388403 _api .check_in_list (
389404 ['uniform' , 'proportional' ], spacing = spacing )
390405
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+
391413 self .ax = ax
392414 self .ax ._axes_locator = _ColorbarAxesLocator (self )
393415
@@ -445,7 +467,11 @@ def __init__(self, ax, mappable=None, *, cmap=None,
445467 self .__scale = None # linear, log10 for now. Hopefully more?
446468
447469 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
449475 self .ticklocation = ticklocation
450476
451477 self .set_label (label )
0 commit comments