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 must match
47
+ *orientation*. For example, a horizontal colorbar can only have ticks at
48
+ 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
@@ -246,13 +251,18 @@ class Colorbar:
246
251
alpha : float
247
252
The colorbar transparency between 0 (transparent) and 1 (opaque).
248
253
249
- orientation : {'vertical', 'horizontal'}
254
+ orientation : None or {'vertical', 'horizontal'}
255
+ If None, use the value determined by *location*. If both
256
+ *orientation* and *location* are None then defaults to 'vertical'.
250
257
251
258
ticklocation : {'auto', 'left', 'right', 'top', 'bottom'}
252
259
253
260
drawedges : bool
254
261
255
262
filled : bool
263
+
264
+ location : None or {'left', 'right', 'top', 'bottom'}
265
+
256
266
%(_colormap_kw_doc)s
257
267
"""
258
268
@@ -264,7 +274,7 @@ def __init__(self, ax, mappable=None, *, cmap=None,
264
274
alpha = None ,
265
275
values = None ,
266
276
boundaries = None ,
267
- orientation = 'vertical' ,
277
+ orientation = None ,
268
278
ticklocation = 'auto' ,
269
279
extend = None ,
270
280
spacing = 'uniform' , # uniform or proportional
@@ -275,6 +285,7 @@ def __init__(self, ax, mappable=None, *, cmap=None,
275
285
extendfrac = None ,
276
286
extendrect = False ,
277
287
label = '' ,
288
+ location = None ,
278
289
):
279
290
280
291
if mappable is None :
@@ -305,14 +316,23 @@ def __init__(self, ax, mappable=None, *, cmap=None,
305
316
mappable .colorbar_cid = mappable .callbacks .connect (
306
317
'changed' , self .update_normal )
307
318
319
+ location_orientation = _get_orientation_from_location (location )
320
+
308
321
_api .check_in_list (
309
- ['vertical' , 'horizontal' ], orientation = orientation )
322
+ [None , 'vertical' , 'horizontal' ], orientation = orientation )
310
323
_api .check_in_list (
311
324
['auto' , 'left' , 'right' , 'top' , 'bottom' ],
312
325
ticklocation = ticklocation )
313
326
_api .check_in_list (
314
327
['uniform' , 'proportional' ], spacing = spacing )
315
328
329
+ if location_orientation is not None and orientation is not None :
330
+ if location_orientation != orientation :
331
+ raise TypeError (
332
+ "location and orientation are mutually exclusive" )
333
+ else :
334
+ orientation = orientation or location_orientation or "vertical"
335
+
316
336
self .ax = ax
317
337
self .ax ._axes_locator = _ColorbarAxesLocator (self )
318
338
@@ -365,7 +385,8 @@ def __init__(self, ax, mappable=None, *, cmap=None,
365
385
self .__scale = None # linear, log10 for now. Hopefully more?
366
386
367
387
if ticklocation == 'auto' :
368
- ticklocation = 'bottom' if orientation == 'horizontal' else 'right'
388
+ ticklocation = _get_ticklocation_from_orientation (
389
+ orientation ) if location is None else location
369
390
self .ticklocation = ticklocation
370
391
371
392
self .set_label (label )
@@ -1330,25 +1351,36 @@ def drag_pan(self, button, key, x, y):
1330
1351
1331
1352
def _normalize_location_orientation (location , orientation ):
1332
1353
if location is None :
1333
- location = _api .check_getitem (
1334
- {None : "right" , "vertical" : "right" , "horizontal" : "bottom" },
1335
- orientation = orientation )
1354
+ location = _get_ticklocation_from_orientation (orientation )
1336
1355
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 },
1356
+ "left" : {"location" : "left" , "anchor " : ( 1.0 , 0.5 ) ,
1357
+ "panchor" : (0.0 , 0.5 ), "pad" : 0.10 },
1358
+ "right" : {"location" : "right" , "anchor " : ( 0.0 , 0.5 ) ,
1359
+ "panchor" : (1.0 , 0.5 ), "pad" : 0.05 },
1360
+ "top" : {"location" : "top" , "anchor " : ( 0.5 , 0.0 ) ,
1361
+ "panchor" : (0.5 , 1.0 ), "pad" : 0.05 },
1362
+ "bottom" : {"location" : "bottom" , "anchor " : ( 0.5 , 1.0 ) ,
1363
+ "panchor" : (0.5 , 0.0 ), "pad" : 0.15 },
1345
1364
}, location = location )
1365
+ loc_settings ["orientation" ] = _get_orientation_from_location (location )
1346
1366
if orientation is not None and orientation != loc_settings ["orientation" ]:
1347
1367
# Allow the user to pass both if they are consistent.
1348
1368
raise TypeError ("location and orientation are mutually exclusive" )
1349
1369
return loc_settings
1350
1370
1351
1371
1372
+ def _get_orientation_from_location (location ):
1373
+ return _api .check_getitem (
1374
+ {None : None , "left" : "vertical" , "right" : "vertical" ,
1375
+ "top" : "horizontal" , "bottom" : "horizontal" }, location = location )
1376
+
1377
+
1378
+ def _get_ticklocation_from_orientation (orientation ):
1379
+ return _api .check_getitem (
1380
+ {None : "right" , "vertical" : "right" , "horizontal" : "bottom" },
1381
+ orientation = orientation )
1382
+
1383
+
1352
1384
@_docstring .interpd
1353
1385
def make_axes (parents , location = None , orientation = None , fraction = 0.15 ,
1354
1386
shrink = 1.0 , aspect = 20 , ** kwargs ):
0 commit comments