Skip to content

Commit 0607414

Browse files
committed
Figure.colorbar: Add parameters position/width/height and more to specify colorbar position and properties
1 parent 3dd7379 commit 0607414

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

pygmt/src/colorbar.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pygmt.alias import Alias, AliasSystem
99
from pygmt.clib import Session
1010
from pygmt.helpers import build_arg_list, fmt_docstring, use_alias
11-
from pygmt.params import Box
11+
from pygmt.params import Box, Position
1212

1313
__doctest_skip__ = ["colorbar"]
1414

@@ -17,19 +17,27 @@
1717
@use_alias(C="cmap", D="position", L="equalsize", Z="zfile")
1818
def colorbar( # noqa: PLR0913
1919
self,
20+
position: Position | None = None,
21+
length: float | None = None,
22+
width: float | None = None,
23+
orientation: Literal["horizontal", "vertical"] = "vertical",
24+
reverse: bool = False,
25+
nan_rectangle=False,
26+
sidebar_triangles=None,
27+
move_annots=None,
28+
box: Box | bool = False,
2029
truncate: Sequence[float] | None = None,
2130
shading: float | Sequence[float] | bool = False,
2231
log: bool = False,
2332
scale: float | None = None,
2433
projection: str | None = None,
25-
box: Box | bool = False,
26-
frame: str | Sequence[str] | bool = False,
2734
region: Sequence[float | str] | str | None = None,
35+
frame: str | Sequence[str] | bool = False,
2836
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
2937
| bool = False,
3038
panel: int | Sequence[int] | bool = False,
31-
transparency: float | None = None,
3239
perspective: float | Sequence[float] | str | bool = False,
40+
transparency: float | None = None,
3341
**kwargs,
3442
):
3543
r"""
@@ -162,7 +170,22 @@ def colorbar( # noqa: PLR0913
162170
"""
163171
self._activate_figure()
164172

173+
_dimension = (length, width) if width is not None else length
174+
165175
aliasdict = AliasSystem(
176+
D=[
177+
Alias(position, name="position"),
178+
Alias(_dimension, name="width/height", prefix="+w", sep="/", size=2),
179+
Alias(
180+
orientation,
181+
name="orientation",
182+
mapping={"horizontal": "+h", "vertical": "+v"},
183+
),
184+
Alias(reverse, name="reverse", prefix="+r"),
185+
Alias(nan_rectangle, name="nan_rectangle", prefix="+n"),
186+
Alias(sidebar_triangles, name="sidebar_triangles", prefix="+e"),
187+
Alias(move_annots, name="move_annots", prefix="+m"),
188+
],
166189
F=Alias(box, name="box"),
167190
G=Alias(truncate, name="truncate", sep="/", size=2),
168191
I=Alias(shading, name="shading", sep="/", size=2),

0 commit comments

Comments
 (0)