diff --git a/pygmt/src/logo.py b/pygmt/src/logo.py index d65bf3bc775..230a23555a8 100644 --- a/pygmt/src/logo.py +++ b/pygmt/src/logo.py @@ -2,7 +2,13 @@ logo - Plot the GMT logo. """ +from collections.abc import Sequence +from typing import Literal + +from pygmt._typing import AnchorCode +from pygmt.alias import Alias, AliasSystem from pygmt.clib import Session +from pygmt.exceptions import GMTInvalidInput from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias @@ -10,7 +16,6 @@ @use_alias( R="region", J="projection", - D="position", F="box", S="style", V="verbose", @@ -18,7 +23,18 @@ t="transparency", ) @kwargs_to_strings(R="sequence", c="sequence_comma", p="sequence") -def logo(self, **kwargs): +def logo( + self, + position: Sequence[str | float] | AnchorCode, + position_type: Literal[ + "mapcoords", "boxcoords", "plotcoords", "inside", "outside" + ] = "mapcoords", + height=None, + width=None, + justify=None, + anchor_offset=None, + **kwargs, +): r""" Plot the GMT logo. @@ -35,10 +51,24 @@ def logo(self, **kwargs): ---------- {projection} {region} - position : str - [**g**\|\ **j**\|\ **J**\|\ **n**\|\ **x**]\ *refpoint*\ - **+w**\ *width*\ [**+j**\ *justify*]\ [**+o**\ *dx*\ [/*dy*]]. - Set reference point on the map for the image. + position/position_type + Location of the GMT logo. The actual meaning of this parameter depends on the + ``position_type`` parameter. + - ``position_type="mapcoords"``: *position* is given as (x, y) in user + coordinates. + - ``position_type="boxcoords"``: *position* is given as (nx, ny) in normalized + coordinates, where (0, 0) is the lower-left corner and (1, 1) is the + upper-right corner of the plot. + - ``position_type="plotcoords"``: *position* is given as (x, y) in plot + coordinates, i.e., the distances in inches, centimeters, or points from the + lower left plot origin. + - ``position_type="inside"``: *position* is given as a two-character + justification code, meaning the anchor point of the rose is inside the plot + bounding box. + - ``position_type="outside"``: *position* is given as a two-character + justification code, but the rose is outside the plot bounding box. + width/height + Width or height of the GMT logo. box : bool or str If set to ``True``, draw a rectangular border around the GMT logo. @@ -55,5 +85,30 @@ def logo(self, **kwargs): {transparency} """ self._activate_figure() + if width is not None and height is not None: + msg = "Cannot specify both width and height." + raise GMTInvalidInput(msg) + + aliasdict = AliasSystem( + D=[ + Alias( + position_type, + name="position_type", + mapping={ + "mapcoords": "g", + "boxcoords": "n", + "plotcoords": "x", + "inside": "j", + "outside": "J", + }, + ), + Alias(position, name="position", sep="/"), + Alias(height, name="height", prefix="+h"), + Alias(width, name="width", prefix="+w"), + Alias(justify, name="justify", prefix="+j"), + Alias(anchor_offset, name="anchor_offset", prefix="+o", sep="/", size=2), + ] + ).merge(kwargs) + with Session() as lib: - lib.call_module(module="logo", args=build_arg_list(kwargs)) + lib.call_module(module="logo", args=build_arg_list(aliasdict)) diff --git a/pygmt/tests/test_logo.py b/pygmt/tests/test_logo.py index 62bddf4eb24..bcd803d8252 100644 --- a/pygmt/tests/test_logo.py +++ b/pygmt/tests/test_logo.py @@ -24,5 +24,11 @@ def test_logo_on_a_map(): """ fig = Figure() fig.basemap(region=[-90, -70, 0, 20], projection="M15c", frame=True) - fig.logo(position="jTR+o0.25c/0.25c+w7.5c", box=True) + fig.logo( + position_type="justify", + position="TR", + offset=(0.25, 0.25), + width="7.5c", + box=True, + ) return fig