Skip to content

Commit e0c306f

Browse files
authored
Figure.timestamp: Add type hints to parameters (#2890)
1 parent b561e9d commit e0c306f

File tree

1 file changed

+45
-41
lines changed

1 file changed

+45
-41
lines changed

pygmt/src/timestamp.py

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,69 @@
11
"""
22
timestamp - Plot the GMT timestamp logo.
33
"""
4+
from __future__ import annotations
5+
46
import warnings
7+
from typing import TYPE_CHECKING
58

69
from packaging.version import Version
710
from pygmt.clib import Session, __gmt_version__
811
from pygmt.helpers import build_arg_string, kwargs_to_strings
912

13+
if TYPE_CHECKING:
14+
from collections.abc import Sequence
15+
16+
1017
__doctest_skip__ = ["timestamp"]
1118

1219

1320
@kwargs_to_strings(offset="sequence")
1421
def timestamp(
1522
self,
16-
text=None,
17-
label=None,
18-
justification="BL",
19-
offset=("-54p", "-54p"),
20-
font="Helvetica,black",
21-
timefmt="%Y %b %d %H:%M:%S",
22-
):
23+
text: str | None = None,
24+
label: str | None = None,
25+
justification: str = "BL",
26+
offset: float | str | Sequence[float | str] = ("-54p", "-54p"),
27+
font: str = "Helvetica,black",
28+
timefmt: str = "%Y %b %d %H:%M:%S",
29+
) -> None:
2330
r"""
2431
Plot the GMT timestamp logo.
2532
26-
Add the GMT timestamp logo with an optional label at the bottom-left corner
27-
of a plot with an offset of ``("-54p", "-54p")``. The timestamp will be
28-
in the locale set by the environment variable **TZ** (generally local time
29-
but can be changed via ``os.environ["TZ"]``) and its format is controlled
30-
by the ``timefmt`` parameter. It can also be replaced with any custom
31-
text string using the ``text`` parameter.
33+
Add the GMT timestamp logo with an optional label at the bottom-left corner of a
34+
plot with an offset of ``("-54p", "-54p")``. The timestamp will be in the locale set
35+
by the environment variable **TZ** (generally local time but can be changed via
36+
``os.environ["TZ"]``) and its format is controlled by the ``timefmt`` parameter. It
37+
can also be replaced with any custom text string using the ``text`` parameter.
3238
3339
Parameters
3440
----------
35-
text : None or str
36-
If ``None``, the current UNIX timestamp is shown in the GMT timestamp
37-
logo. Set this parameter to replace the UNIX timestamp with a custom
38-
text string instead. The text must be no longer than 64 characters.
39-
label : None or str
41+
text
42+
If ``None``, the current UNIX timestamp is shown in the GMT timestamp logo. Set
43+
this parameter to replace the UNIX timestamp with a custom text string instead.
44+
The text must be no longer than 64 characters.
45+
label
4046
The text string shown after the GMT timestamp logo.
41-
justification : str
42-
Justification of the timestamp box relative to the plot's bottom-left
43-
corner (i.e., the plot origin). The *justification* is a two-character
44-
code that is a combination of a horizontal (**L**\ (eft),
45-
**C**\ (enter), or **R**\ (ight)) and a vertical (**T**\ (op),
46-
**M**\ (iddle), or **B**\ (ottom)) code. For example,
47-
``justification="TL"`` means choosing the **T**\ op **L**\ eft point of
48-
the timestamp as the anchor point.
49-
offset : str or list
50-
*offset* or [*offset_x*, *offset_y*].
51-
Offset the anchor point of the timestamp box by *offset_x* and
52-
*offset_y*. If a single value *offset* is given, *offset_y* =
53-
*offset_x* = *offset*.
54-
font : str
55-
Font of the timestamp and the optional label. Since the GMT logo has a
56-
fixed height, the font sizes are fixed to be 8-point for the timestamp
57-
and 7-point for the label. The parameter can't change the font color
58-
for GMT<=6.4.0, only the font style.
59-
timefmt : str
60-
Format string for the UNIX timestamp. The format string is parsed by
61-
the C function ``strftime``, so that virtually any text can be used
62-
(even not containing any time information).
47+
justification
48+
Justification of the timestamp box relative to the plot's bottom-left corner
49+
(i.e., the plot origin). The *justification* is a two-character code that is a
50+
combination of a horizontal (**L**\ (eft), **C**\ (enter), or **R**\ (ight)) and
51+
a vertical (**T**\ (op), **M**\ (iddle), or **B**\ (ottom)) code. For example,
52+
``justification="TL"`` means choosing the **T**\ op **L**\ eft point of the
53+
timestamp as the anchor point.
54+
offset
55+
*offset* or (*offset_x*, *offset_y*).
56+
Offset the anchor point of the timestamp box by *offset_x* and *offset_y*. If a
57+
single value *offset* is given, *offset_y* = *offset_x* = *offset*.
58+
font
59+
Font of the timestamp and the optional label. Since the GMT logo has a fixed
60+
height, the font sizes are fixed to be 8-point for the timestamp and 7-point for
61+
the label. The parameter can't change the font color for GMT<=6.4.0, only the
62+
font style.
63+
timefmt
64+
Format string for the UNIX timestamp. The format string is parsed by the C
65+
function ``strftime``, so that virtually any text can be used (even not
66+
containing any time information).
6367
6468
Examples
6569
--------
@@ -79,7 +83,7 @@ def timestamp(
7983
self._preprocess()
8084

8185
# Build the options passed to the "plot" module
82-
kwdict = {"T": True, "U": ""}
86+
kwdict: dict = {"T": True, "U": ""}
8387
if label is not None:
8488
kwdict["U"] += f"{label}"
8589
kwdict["U"] += f"+j{justification}"

0 commit comments

Comments
 (0)