Skip to content

Commit aef85bf

Browse files
committed
Figure.logo: Refactor using the AliasSystem class
1 parent 5259b1e commit aef85bf

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

pygmt/src/logo.py

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,37 @@
22
logo - Plot the GMT logo.
33
"""
44

5+
from typing import Literal
6+
7+
from pygmt.alias import Alias, AliasSystem
58
from pygmt.clib import Session
9+
from pygmt.exceptions import GMTInvalidInput
610
from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias
711

812

913
@fmt_docstring
1014
@use_alias(
1115
R="region",
1216
J="projection",
13-
D="position",
1417
F="box",
1518
S="style",
1619
V="verbose",
1720
c="panel",
1821
t="transparency",
1922
)
2023
@kwargs_to_strings(R="sequence", c="sequence_comma", p="sequence")
21-
def logo(self, **kwargs):
24+
def logo(
25+
self,
26+
position_type: Literal[
27+
"user", "justify", "mirror", "normalize", "plot", None
28+
] = None,
29+
position=None,
30+
height=None,
31+
width=None,
32+
justify=None,
33+
offset=None,
34+
**kwargs,
35+
):
2236
r"""
2337
Plot the GMT logo.
2438
@@ -39,6 +53,9 @@ def logo(self, **kwargs):
3953
[**g**\|\ **j**\|\ **J**\|\ **n**\|\ **x**]\ *refpoint*\
4054
**+w**\ *width*\ [**+j**\ *justify*]\ [**+o**\ *dx*\ [/*dy*]].
4155
Set reference point on the map for the image.
56+
positon_type
57+
width/height
58+
Width or height of the GMT logo.
4259
box : bool or str
4360
If set to ``True``, draw a rectangular border around the
4461
GMT logo.
@@ -55,5 +72,30 @@ def logo(self, **kwargs):
5572
{transparency}
5673
"""
5774
self._activate_figure()
75+
if width is not None and height is not None:
76+
msg = "Cannot specify both width and height."
77+
raise GMTInvalidInput(msg)
78+
79+
aliasdict = AliasSystem(
80+
D=[
81+
Alias(
82+
position_type,
83+
name="position_type",
84+
mapping={
85+
"user": "g",
86+
"justify": "j",
87+
"mirror": "J",
88+
"normalize": "n",
89+
"plot": "x",
90+
},
91+
),
92+
Alias(position, name="position", separator="/"),
93+
Alias(height, name="height", prefix="+h"),
94+
Alias(width, name="width", prefix="+w"),
95+
Alias(justify, name="justify", prefix="+j"),
96+
Alias(offset, name="offset", prefix="+o", separator="/", size=2),
97+
]
98+
).merge(kwargs)
99+
58100
with Session() as lib:
59-
lib.call_module(module="logo", args=build_arg_list(kwargs))
101+
lib.call_module(module="logo", args=build_arg_list(aliasdict))

pygmt/tests/test_logo.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,11 @@ def test_logo_on_a_map():
2424
"""
2525
fig = Figure()
2626
fig.basemap(region=[-90, -70, 0, 20], projection="M15c", frame=True)
27-
fig.logo(position="jTR+o0.25c/0.25c+w7.5c", box=True)
27+
fig.logo(
28+
position_type="justify",
29+
position="TR",
30+
offset=(0.25, 0.25),
31+
width="7.5c",
32+
box=True,
33+
)
2834
return fig

0 commit comments

Comments
 (0)