Skip to content
Merged
Show file tree
Hide file tree
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
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"]
4 changes: 2 additions & 2 deletions pygmt/helpers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import sys
import time
import webbrowser
from collections.abc import Iterable, Sequence
from collections.abc import Iterable, Mapping, Sequence
from typing import Any, Literal

import xarray as xr
Expand Down Expand Up @@ -395,7 +395,7 @@ def non_ascii_to_octal(

def build_arg_list( # noqa: PLR0912
kwdict: dict[str, Any],
confdict: dict[str, str] | None = None,
confdict: Mapping[str, Any] | None = None,
infile: str | pathlib.PurePath | Sequence[str | pathlib.PurePath] | None = None,
outfile: str | pathlib.PurePath | None = None,
) -> list[str]:
Expand Down
13 changes: 8 additions & 5 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,14 +93,14 @@ 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)
code, chosen from:

* Horizontal: **L**\ (eft), **C**\ (entre), **R**\ (ight)
* Vertical: **T**\ (op), **M**\ (iddle), **B**\ (ottom)
* Horizontal: **L**\ (eft), **C**\ (entre), **R**\ (ight)

For example, ``position="TL"`` plots the text at the Top Left corner
of the map.
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