Skip to content

Commit a2a3e3d

Browse files
committed
Improve Figure.scalebar
1 parent 79a0d91 commit a2a3e3d

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

pygmt/src/scalebar.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
scalebar - Add a scale bar.
33
"""
44

5+
from typing import Literal
6+
57
from pygmt.alias import Alias, AliasSystem
68
from pygmt.clib import Session
79
from pygmt.helpers import build_arg_list
@@ -12,6 +14,7 @@ def scalebar( # noqa: PLR0913
1214
self,
1315
position,
1416
length,
17+
position_type: Literal["g", "j", "J", "n", "x"] = "g",
1518
label_alignment=None,
1619
scale_position=None,
1720
fancy=None,
@@ -36,7 +39,8 @@ def scalebar( # noqa: PLR0913
3639
>>> fig = pygmt.Figure()
3740
>>> fig.basemap(region=[0, 80, -30, 30], projection="M10c", frame=True)
3841
>>> fig.scalebar(
39-
... "g10/10",
42+
... position=(10, 10),
43+
... position_type="g",
4044
... length=1000,
4145
... fancy=True,
4246
... label="Scale",
@@ -45,9 +49,9 @@ def scalebar( # noqa: PLR0913
4549
... )
4650
>>> fig.show()
4751
"""
48-
alias = AliasSystem(
52+
kwdict = AliasSystem(
4953
L=[
50-
Alias(position, separator="/"),
54+
Alias(position, separator="/", prefix=position_type),
5155
Alias(length, prefix="+w"),
5256
Alias(label_alignment, prefix="+a"),
5357
Alias(scale_position, prefix="+c", separator="/"),
@@ -59,8 +63,8 @@ def scalebar( # noqa: PLR0913
5963
Alias(vertical, prefix="+v"),
6064
],
6165
F=Alias(box),
62-
)
66+
).kwdict
6367

6468
self._preprocess()
6569
with Session() as lib:
66-
lib.call_module(module="basemap", args=build_arg_list(alias.kwdict))
70+
lib.call_module(module="basemap", args=build_arg_list(kwdict))

0 commit comments

Comments
 (0)