Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion pygmt/src/inset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"""

import contextlib
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.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias
Expand All @@ -22,7 +25,19 @@
V="verbose",
)
@kwargs_to_strings(D="sequence", M="sequence", R="sequence")
def inset(self, projection=None, **kwargs):
def inset(
self,
position: Sequence[str | float] | AnchorCode,
position_type: Literal[
"mapcoords", "boxcoords", "plotcoords", "inside", "outside"
] = "mapcoords",
width: float | str | None = None,
height: float | str | None = None,
justify: AnchorCode | None = None,
anchor_offset: Sequence[float] | None = None,
projection=None,
**kwargs,
):
r"""
Manage figure inset setup and completion.

Expand Down Expand Up @@ -137,7 +152,28 @@ def inset(self, projection=None, **kwargs):
"""
self._activate_figure()

# -D[g|j|J|n|x]refpoint+wwidth[/height][+jjustify][+odx[/dy]]

_dimension = (width, height) if height is not None else width

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="/", size=2),
Alias(_dimension, name="width/height", prefix="+w", sep="/", size=2),
Alias(justify, name="justify", prefix="+j"),
Alias(anchor_offset, name="anchor_offset", prefix="+o", sep="/", size=2),
],
J=Alias(projection, name="projection"),
).merge(kwargs)

Expand Down
Loading