@@ -246,14 +246,35 @@ class Colorbar:
246
246
alpha : float
247
247
The colorbar transparency between 0 (transparent) and 1 (opaque).
248
248
249
- orientation : {'vertical', 'horizontal'}
249
+ orientation : None or {'vertical', 'horizontal'}
250
+ If None, use the value determined by *location*. If both
251
+ *orientation* and *location* are None then defaults to 'vertical'.
250
252
251
253
ticklocation : {'auto', 'left', 'right', 'top', 'bottom'}
254
+ The location of the colorbar ticks. The *ticklocation* must match
255
+ *orientation*. For example, a horizontal colorbar can only have ticks
256
+ at the top or the bottom. If 'auto', the ticks will be the same as
257
+ *location*, so a colorbar to the left will have ticks to the left. If
258
+ *location* is None, the ticks will be at the bottom for a horizontal
259
+ colorbar and at the right for a vertical.
252
260
253
261
drawedges : bool
262
+ Whether to draw lines at color boundaries.
254
263
255
264
filled : bool
265
+
256
266
%(_colormap_kw_doc)s
267
+
268
+ location : None or {'left', 'right', 'top', 'bottom'}
269
+ Set the *orientation* and *ticklocation* of the colorbar using a
270
+ single argument. Colorbars on the left and right are vertical,
271
+ colorbars at the top and bottom are horizontal. The *ticklocation* is
272
+ the same as *location*, so if *location* is 'top', the ticks are on
273
+ the top. *orientation* and/or *ticklocation* can be provided as well
274
+ and overrides the value set by *location*, but there will be an error
275
+ for incompatible combinations.
276
+
277
+ .. versionadded:: 3.7
257
278
"""
258
279
259
280
n_rasterize = 50 # rasterize solids if number of colors >= n_rasterize
@@ -264,7 +285,7 @@ def __init__(self, ax, mappable=None, *, cmap=None,
264
285
alpha = None ,
265
286
values = None ,
266
287
boundaries = None ,
267
- orientation = 'vertical' ,
288
+ orientation = None ,
268
289
ticklocation = 'auto' ,
269
290
extend = None ,
270
291
spacing = 'uniform' , # uniform or proportional
@@ -275,6 +296,7 @@ def __init__(self, ax, mappable=None, *, cmap=None,
275
296
extendfrac = None ,
276
297
extendrect = False ,
277
298
label = '' ,
299
+ location = None ,
278
300
):
279
301
280
302
if mappable is None :
@@ -305,14 +327,23 @@ def __init__(self, ax, mappable=None, *, cmap=None,
305
327
mappable .colorbar_cid = mappable .callbacks .connect (
306
328
'changed' , self .update_normal )
307
329
330
+ location_orientation = _get_orientation_from_location (location )
331
+
308
332
_api .check_in_list (
309
- ['vertical' , 'horizontal' ], orientation = orientation )
333
+ [None , 'vertical' , 'horizontal' ], orientation = orientation )
310
334
_api .check_in_list (
311
335
['auto' , 'left' , 'right' , 'top' , 'bottom' ],
312
336
ticklocation = ticklocation )
313
337
_api .check_in_list (
314
338
['uniform' , 'proportional' ], spacing = spacing )
315
339
340
+ if location_orientation is not None and orientation is not None :
341
+ if location_orientation != orientation :
342
+ raise TypeError (
343
+ "location and orientation are mutually exclusive" )
344
+ else :
345
+ orientation = orientation or location_orientation or "vertical"
346
+
316
347
self .ax = ax
317
348
self .ax ._axes_locator = _ColorbarAxesLocator (self )
318
349
@@ -365,7 +396,8 @@ def __init__(self, ax, mappable=None, *, cmap=None,
365
396
self .__scale = None # linear, log10 for now. Hopefully more?
366
397
367
398
if ticklocation == 'auto' :
368
- ticklocation = 'bottom' if orientation == 'horizontal' else 'right'
399
+ ticklocation = _get_ticklocation_from_orientation (
400
+ orientation ) if location is None else location
369
401
self .ticklocation = ticklocation
370
402
371
403
self .set_label (label )
@@ -1330,25 +1362,36 @@ def drag_pan(self, button, key, x, y):
1330
1362
1331
1363
def _normalize_location_orientation (location , orientation ):
1332
1364
if location is None :
1333
- location = _api .check_getitem (
1334
- {None : "right" , "vertical" : "right" , "horizontal" : "bottom" },
1335
- orientation = orientation )
1365
+ location = _get_ticklocation_from_orientation (orientation )
1336
1366
loc_settings = _api .check_getitem ({
1337
- "left" : {"location" : "left" , "orientation " : "vertical" ,
1338
- "anchor" : ( 1.0 , 0.5 ), " panchor" : (0.0 , 0.5 ), "pad" : 0.10 },
1339
- "right" : {"location" : "right" , "orientation " : "vertical" ,
1340
- "anchor" : ( 0.0 , 0.5 ), " panchor" : (1.0 , 0.5 ), "pad" : 0.05 },
1341
- "top" : {"location" : "top" , "orientation " : "horizontal" ,
1342
- "anchor" : ( 0.5 , 0.0 ), " panchor" : (0.5 , 1.0 ), "pad" : 0.05 },
1343
- "bottom" : {"location" : "bottom" , "orientation " : "horizontal" ,
1344
- "anchor" : ( 0.5 , 1.0 ), " panchor" : (0.5 , 0.0 ), "pad" : 0.15 },
1367
+ "left" : {"location" : "left" , "anchor " : ( 1.0 , 0.5 ) ,
1368
+ "panchor" : (0.0 , 0.5 ), "pad" : 0.10 },
1369
+ "right" : {"location" : "right" , "anchor " : ( 0.0 , 0.5 ) ,
1370
+ "panchor" : (1.0 , 0.5 ), "pad" : 0.05 },
1371
+ "top" : {"location" : "top" , "anchor " : ( 0.5 , 0.0 ) ,
1372
+ "panchor" : (0.5 , 1.0 ), "pad" : 0.05 },
1373
+ "bottom" : {"location" : "bottom" , "anchor " : ( 0.5 , 1.0 ) ,
1374
+ "panchor" : (0.5 , 0.0 ), "pad" : 0.15 },
1345
1375
}, location = location )
1376
+ loc_settings ["orientation" ] = _get_orientation_from_location (location )
1346
1377
if orientation is not None and orientation != loc_settings ["orientation" ]:
1347
1378
# Allow the user to pass both if they are consistent.
1348
1379
raise TypeError ("location and orientation are mutually exclusive" )
1349
1380
return loc_settings
1350
1381
1351
1382
1383
+ def _get_orientation_from_location (location ):
1384
+ return _api .check_getitem (
1385
+ {None : None , "left" : "vertical" , "right" : "vertical" ,
1386
+ "top" : "horizontal" , "bottom" : "horizontal" }, location = location )
1387
+
1388
+
1389
+ def _get_ticklocation_from_orientation (orientation ):
1390
+ return _api .check_getitem (
1391
+ {None : "right" , "vertical" : "right" , "horizontal" : "bottom" },
1392
+ orientation = orientation )
1393
+
1394
+
1352
1395
@_docstring .interpd
1353
1396
def make_axes (parents , location = None , orientation = None , fraction = 0.15 ,
1354
1397
shrink = 1.0 , aspect = 20 , ** kwargs ):
0 commit comments