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* must match
47
+ *orientation*. For example, a horizontal colorbar can only have ticks at
48
+ the top or the bottom. If 'auto', the ticks will be the same as *location*,
49
+ so a colorbar to the left will have ticks to the left. If *location* is
50
+ None, the ticks will be at the bottom for horizontal colorbar and at the
51
+ right for a vertical.
52
+
45
53
fraction : float, default: 0.15
46
54
Fraction of original axes to use for colorbar.
47
55
@@ -246,13 +254,31 @@ class Colorbar:
246
254
alpha : float
247
255
The colorbar transparency between 0 (transparent) and 1 (opaque).
248
256
249
- 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 then defaults to 'vertical'.
250
260
251
261
ticklocation : {'auto', 'left', 'right', 'top', 'bottom'}
262
+ The location of the colorbar ticks. The *ticklocation* must match
263
+ *orientation*. For example, a horizontal colorbar can only have ticks
264
+ at the top or the bottom. If 'auto', the ticks will be the same as
265
+ *location*, so a colorbar to the left will have ticks to the left. If
266
+ *location* is None, the ticks will be at the bottom for horizontal
267
+ colorbar and at the right for a vertical.
252
268
253
269
drawedges : bool
270
+ Whether to draw lines at color boundaries.
254
271
255
272
filled : bool
273
+
274
+ location : None or {'left', 'right', 'top', 'bottom'}
275
+ The location, relative to the parent axes, where the colorbar axes
276
+ is created. It also determines the *orientation* of the colorbar
277
+ (colorbars on the left and right are vertical, colorbars at the top
278
+ and bottom are horizontal). If None, the location will come from the
279
+ *orientation* if it is set (vertical colorbars on the right, horizontal
280
+ ones at the bottom), or default to 'right' if *orientation* is unset.
281
+
256
282
%(_colormap_kw_doc)s
257
283
"""
258
284
@@ -264,7 +290,7 @@ def __init__(self, ax, mappable=None, *, cmap=None,
264
290
alpha = None ,
265
291
values = None ,
266
292
boundaries = None ,
267
- orientation = 'vertical' ,
293
+ orientation = None ,
268
294
ticklocation = 'auto' ,
269
295
extend = None ,
270
296
spacing = 'uniform' , # uniform or proportional
@@ -275,6 +301,7 @@ def __init__(self, ax, mappable=None, *, cmap=None,
275
301
extendfrac = None ,
276
302
extendrect = False ,
277
303
label = '' ,
304
+ location = None ,
278
305
):
279
306
280
307
if mappable is None :
@@ -305,14 +332,23 @@ def __init__(self, ax, mappable=None, *, cmap=None,
305
332
mappable .colorbar_cid = mappable .callbacks .connect (
306
333
'changed' , self .update_normal )
307
334
335
+ location_orientation = _get_orientation_from_location (location )
336
+
308
337
_api .check_in_list (
309
- ['vertical' , 'horizontal' ], orientation = orientation )
338
+ [None , 'vertical' , 'horizontal' ], orientation = orientation )
310
339
_api .check_in_list (
311
340
['auto' , 'left' , 'right' , 'top' , 'bottom' ],
312
341
ticklocation = ticklocation )
313
342
_api .check_in_list (
314
343
['uniform' , 'proportional' ], spacing = spacing )
315
344
345
+ if location_orientation is not None and orientation is not None :
346
+ if location_orientation != orientation :
347
+ raise TypeError (
348
+ "location and orientation are mutually exclusive" )
349
+ else :
350
+ orientation = orientation or location_orientation or "vertical"
351
+
316
352
self .ax = ax
317
353
self .ax ._axes_locator = _ColorbarAxesLocator (self )
318
354
@@ -365,7 +401,8 @@ def __init__(self, ax, mappable=None, *, cmap=None,
365
401
self .__scale = None # linear, log10 for now. Hopefully more?
366
402
367
403
if ticklocation == 'auto' :
368
- ticklocation = 'bottom' if orientation == 'horizontal' else 'right'
404
+ ticklocation = _get_ticklocation_from_orientation (
405
+ orientation ) if location is None else location
369
406
self .ticklocation = ticklocation
370
407
371
408
self .set_label (label )
@@ -1330,25 +1367,36 @@ def drag_pan(self, button, key, x, y):
1330
1367
1331
1368
def _normalize_location_orientation (location , orientation ):
1332
1369
if location is None :
1333
- location = _api .check_getitem (
1334
- {None : "right" , "vertical" : "right" , "horizontal" : "bottom" },
1335
- orientation = orientation )
1370
+ location = _get_ticklocation_from_orientation (orientation )
1336
1371
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 },
1372
+ "left" : {"location" : "left" , "anchor " : ( 1.0 , 0.5 ) ,
1373
+ "panchor" : (0.0 , 0.5 ), "pad" : 0.10 },
1374
+ "right" : {"location" : "right" , "anchor " : ( 0.0 , 0.5 ) ,
1375
+ "panchor" : (1.0 , 0.5 ), "pad" : 0.05 },
1376
+ "top" : {"location" : "top" , "anchor " : ( 0.5 , 0.0 ) ,
1377
+ "panchor" : (0.5 , 1.0 ), "pad" : 0.05 },
1378
+ "bottom" : {"location" : "bottom" , "anchor " : ( 0.5 , 1.0 ) ,
1379
+ "panchor" : (0.5 , 0.0 ), "pad" : 0.15 },
1345
1380
}, location = location )
1381
+ loc_settings ["orientation" ] = _get_orientation_from_location (location )
1346
1382
if orientation is not None and orientation != loc_settings ["orientation" ]:
1347
1383
# Allow the user to pass both if they are consistent.
1348
1384
raise TypeError ("location and orientation are mutually exclusive" )
1349
1385
return loc_settings
1350
1386
1351
1387
1388
+ def _get_orientation_from_location (location ):
1389
+ return _api .check_getitem (
1390
+ {None : None , "left" : "vertical" , "right" : "vertical" ,
1391
+ "top" : "horizontal" , "bottom" : "horizontal" }, location = location )
1392
+
1393
+
1394
+ def _get_ticklocation_from_orientation (orientation ):
1395
+ return _api .check_getitem (
1396
+ {None : "right" , "vertical" : "right" , "horizontal" : "bottom" },
1397
+ orientation = orientation )
1398
+
1399
+
1352
1400
@_docstring .interpd
1353
1401
def make_axes (parents , location = None , orientation = None , fraction = 0.15 ,
1354
1402
shrink = 1.0 , aspect = 20 , ** kwargs ):
0 commit comments