Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type hints for GMT anchor codes #3459

Merged
merged 4 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions pygmt/_typing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
Type aliases for type hints.
"""

from typing import Literal

# Anchor codes
AnchorCode = Literal["TL", "TC", "TR", "ML", "MC", "MR", "BL", "BC", "BR"]
11 changes: 7 additions & 4 deletions pygmt/src/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
text - Plot text on a figure.
"""

from collections.abc import Sequence

import numpy as np
from pygmt._typing import AnchorCode
from pygmt.clib import Session
from pygmt.exceptions import GMTInvalidInput
from pygmt.helpers import (
Expand Down Expand Up @@ -44,11 +47,11 @@ def text_( # noqa: PLR0912
textfiles=None,
x=None,
y=None,
position=None,
position: AnchorCode | None = None,
text=None,
angle=None,
font=None,
justify=None,
justify: bool | None | AnchorCode | Sequence[AnchorCode] = None,
**kwargs,
):
r"""
Expand Down Expand Up @@ -90,7 +93,7 @@ def text_( # noqa: PLR0912
x/y : float or 1-D arrays
The x and y coordinates, or an array of x and y coordinates to plot
the text.
position : str
position
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nit, could you reverse the order of L102 and L103 below, so that Vertical (TMD) is on top of Horizontal (LCR)?

Set reference point on the map for the text by using x, y
coordinates extracted from ``region`` instead of providing them
through ``x``/``y``. Specify with a two-letter (order independent)
Expand All @@ -116,7 +119,7 @@ def text_( # noqa: PLR0912
font. If no font info is explicitly given (i.e. ``font=True``), then
the input to ``textfiles`` must have this information in one of its
columns.
justify : str, bool or list of str
justify
Set the alignment which refers to the part of the text string that
will be mapped onto the (x, y) point. Choose a two-letter
combination of **L**, **C**, **R** (for left, center, or right) and
Expand Down
3 changes: 2 additions & 1 deletion pygmt/src/timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from collections.abc import Sequence

from packaging.version import Version
from pygmt._typing import AnchorCode
from pygmt.clib import Session, __gmt_version__
from pygmt.helpers import build_arg_list, kwargs_to_strings

Expand All @@ -17,7 +18,7 @@ def timestamp(
self,
text: str | None = None,
label: str | None = None,
justify: str = "BL",
justify: AnchorCode = "BL",
offset: float | str | Sequence[float | str] = ("-54p", "-54p"),
font: str = "Helvetica,black",
timefmt: str = "%Y %b %d %H:%M:%S",
Expand Down
Loading