Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbdb43a3

Browse files
committed
Add location keyword argument to Colorbar
1 parent806d407 commitbdb43a3

File tree

4 files changed

+377
-4
lines changed

4 files changed

+377
-4
lines changed

‎lib/matplotlib/colorbar.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@
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+
4550
fraction : 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
ifmappableisNone:
@@ -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+
iflocation_orientationisnotNoneandorientationisnotNone:
407+
iflocation_orientation!=orientation:
408+
raiseTypeError(
409+
"location and orientation are mutually exclusive")
410+
else:
411+
orientation=orientationorlocation_orientationor"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
ifticklocation=='auto':
448-
ticklocation='bottom'iforientation=='horizontal'else'right'
470+
iflocationisNone:
471+
ticklocation= (
472+
'bottom'iforientation=='horizontal'else'right')
473+
else:
474+
ticklocation=location
449475
self.ticklocation=ticklocation
450476

451477
self.set_label(label)
Lines changed: 308 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp