Skip to content

Commit eb32c40

Browse files
committed
Update legend
1 parent fef7c00 commit eb32c40

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

pygmt/src/legend.py

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,18 @@
22
legend - Plot a legend.
33
"""
44

5+
from pygmt.alias import Alias, convert_aliases
56
from pygmt.clib import Session
67
from pygmt.exceptions import GMTInvalidInput
78
from pygmt.helpers import (
89
build_arg_string,
910
data_kind,
1011
fmt_docstring,
11-
kwargs_to_strings,
12-
use_alias,
1312
)
1413

1514

1615
@fmt_docstring
17-
@use_alias(
18-
R="region",
19-
J="projection",
20-
D="position",
21-
F="box",
22-
V="verbose",
23-
c="panel",
24-
p="perspective",
25-
t="transparency",
26-
)
27-
@kwargs_to_strings(R="sequence", c="sequence_comma", p="sequence")
28-
def legend(self, spec=None, position="JTR+jTR+o0.2c", box="+gwhite+p1p", **kwargs):
16+
def legend(self, spec=None, position="JTR+jTR+o0.2c", box="+gwhite+p1p", **kwargs): # noqa: ARG001
2917
r"""
3018
Plot legends on maps.
3119
@@ -37,8 +25,6 @@ def legend(self, spec=None, position="JTR+jTR+o0.2c", box="+gwhite+p1p", **kwarg
3725
3826
Full option list at :gmt-docs:`legend.html`
3927
40-
{aliases}
41-
4228
Parameters
4329
----------
4430
spec : None or str
@@ -67,12 +53,19 @@ def legend(self, spec=None, position="JTR+jTR+o0.2c", box="+gwhite+p1p", **kwarg
6753
{perspective}
6854
{transparency}
6955
"""
70-
kwargs = self._preprocess(**kwargs)
56+
_aliases = [
57+
Alias("region", "R", "", "/"),
58+
Alias("projection", "J", "", ""),
59+
Alias("position", "D", "", ""),
60+
Alias("box", "F", "", ""),
61+
Alias("verbose", "v", "", ""),
62+
Alias("panel", "c", "", ","),
63+
Alias("perspective", "p", "", "/"),
64+
Alias("transparency", "t", "", ""),
65+
]
7166

72-
if kwargs.get("D") is None:
73-
kwargs["D"] = position
74-
if kwargs.get("F") is None:
75-
kwargs["F"] = box
67+
kwargs = self._preprocess(**kwargs)
68+
options = convert_aliases()
7669

7770
with Session() as lib:
7871
if spec is None:
@@ -81,4 +74,6 @@ def legend(self, spec=None, position="JTR+jTR+o0.2c", box="+gwhite+p1p", **kwarg
8174
specfile = spec
8275
else:
8376
raise GMTInvalidInput(f"Unrecognized data type: {type(spec)}")
84-
lib.call_module(module="legend", args=build_arg_string(kwargs, infile=specfile))
77+
lib.call_module(
78+
module="legend", args=build_arg_string(options, infile=specfile)
79+
)

0 commit comments

Comments
 (0)