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
@@ -249,13 +254,19 @@ class Colorbar:
249
254
alpha : float
250
255
The colorbar transparency between 0 (transparent) and 1 (opaque).
251
256
252
- orientation : {'vertical', 'horizontal'}
257
+ orientation : None or {'vertical', 'horizontal'}
258
+ If None, use the value determined by *location*. If both
259
+ *orientation* and *location* are None, 'vertical'.
253
260
254
261
ticklocation : {'auto', 'left', 'right', 'top', 'bottom'}
255
262
256
263
drawedges : bool
257
264
258
265
filled : bool
266
+
267
+ location : None or {'left', 'right', 'top', 'bottom'}
268
+ %s
269
+
259
270
%(_colormap_kw_doc)s
260
271
"""
261
272
@@ -267,7 +278,7 @@ def __init__(self, ax, mappable=None, *, cmap=None,
267
278
alpha = None ,
268
279
values = None ,
269
280
boundaries = None ,
270
- orientation = 'vertical' ,
281
+ orientation = None ,
271
282
ticklocation = 'auto' ,
272
283
extend = None ,
273
284
spacing = 'uniform' , # uniform or proportional
@@ -278,6 +289,7 @@ def __init__(self, ax, mappable=None, *, cmap=None,
278
289
extendfrac = None ,
279
290
extendrect = False ,
280
291
label = '' ,
292
+ location = None ,
281
293
):
282
294
283
295
if mappable is None :
@@ -308,14 +320,23 @@ def __init__(self, ax, mappable=None, *, cmap=None,
308
320
mappable .colorbar_cid = mappable .callbacks .connect (
309
321
'changed' , self .update_normal )
310
322
323
+ location_orientation = _get_orientation_from_location (location )
324
+
311
325
_api .check_in_list (
312
- ['vertical' , 'horizontal' ], orientation = orientation )
326
+ [None , 'vertical' , 'horizontal' ], orientation = orientation )
313
327
_api .check_in_list (
314
328
['auto' , 'left' , 'right' , 'top' , 'bottom' ],
315
329
ticklocation = ticklocation )
316
330
_api .check_in_list (
317
331
['uniform' , 'proportional' ], spacing = spacing )
318
332
333
+ if location_orientation is not None and orientation is not None :
334
+ if location_orientation != orientation :
335
+ raise TypeError (
336
+ "location and orientation are mutually exclusive" )
337
+ else :
338
+ orientation = orientation or location_orientation or "vertical"
339
+
319
340
self .ax = ax
320
341
self .ax ._axes_locator = _ColorbarAxesLocator (self )
321
342
@@ -374,7 +395,8 @@ def __init__(self, ax, mappable=None, *, cmap=None,
374
395
self .__scale = None # linear, log10 for now. Hopefully more?
375
396
376
397
if ticklocation == 'auto' :
377
- ticklocation = 'bottom' if orientation == 'horizontal' else 'right'
398
+ ticklocation = _get_ticklocation_from_orientation (
399
+ orientation ) if location is None else location
378
400
self .ticklocation = ticklocation
379
401
380
402
self .set_label (label )
@@ -1335,25 +1357,36 @@ def drag_pan(self, button, key, x, y):
1335
1357
1336
1358
def _normalize_location_orientation (location , orientation ):
1337
1359
if location is None :
1338
- location = _api .check_getitem (
1339
- {None : "right" , "vertical" : "right" , "horizontal" : "bottom" },
1340
- orientation = orientation )
1360
+ location = _get_ticklocation_from_orientation (orientation )
1341
1361
loc_settings = _api .check_getitem ({
1342
- "left" : {"location" : "left" , "orientation " : "vertical" ,
1343
- "anchor" : ( 1.0 , 0.5 ), " panchor" : (0.0 , 0.5 ), "pad" : 0.10 },
1344
- "right" : {"location" : "right" , "orientation " : "vertical" ,
1345
- "anchor" : ( 0.0 , 0.5 ), " panchor" : (1.0 , 0.5 ), "pad" : 0.05 },
1346
- "top" : {"location" : "top" , "orientation " : "horizontal" ,
1347
- "anchor" : ( 0.5 , 0.0 ), " panchor" : (0.5 , 1.0 ), "pad" : 0.05 },
1348
- "bottom" : {"location" : "bottom" , "orientation " : "horizontal" ,
1349
- "anchor" : ( 0.5 , 1.0 ), " panchor" : (0.5 , 0.0 ), "pad" : 0.15 },
1362
+ "left" : {"location" : "left" , "anchor " : ( 1.0 , 0.5 ) ,
1363
+ "panchor" : (0.0 , 0.5 ), "pad" : 0.10 },
1364
+ "right" : {"location" : "right" , "anchor " : ( 0.0 , 0.5 ) ,
1365
+ "panchor" : (1.0 , 0.5 ), "pad" : 0.05 },
1366
+ "top" : {"location" : "top" , "anchor " : ( 0.5 , 0.0 ) ,
1367
+ "panchor" : (0.5 , 1.0 ), "pad" : 0.05 },
1368
+ "bottom" : {"location" : "bottom" , "anchor " : ( 0.5 , 1.0 ) ,
1369
+ "panchor" : (0.5 , 0.0 ), "pad" : 0.15 },
1350
1370
}, location = location )
1371
+ loc_settings ["orientation" ] = _get_orientation_from_location (location )
1351
1372
if orientation is not None and orientation != loc_settings ["orientation" ]:
1352
1373
# Allow the user to pass both if they are consistent.
1353
1374
raise TypeError ("location and orientation are mutually exclusive" )
1354
1375
return loc_settings
1355
1376
1356
1377
1378
+ def _get_orientation_from_location (location ):
1379
+ return _api .check_getitem (
1380
+ {None : None , "left" : "vertical" , "right" : "vertical" ,
1381
+ "top" : "horizontal" , "bottom" : "horizontal" }, location = location )
1382
+
1383
+
1384
+ def _get_ticklocation_from_orientation (orientation ):
1385
+ return _api .check_getitem (
1386
+ {None : "right" , "vertical" : "right" , "horizontal" : "bottom" },
1387
+ orientation = orientation )
1388
+
1389
+
1357
1390
@_docstring .interpd
1358
1391
def make_axes (parents , location = None , orientation = None , fraction = 0.15 ,
1359
1392
shrink = 1.0 , aspect = 20 , ** kwargs ):
0 commit comments