1
1
"""
2
2
timestamp - Plot the GMT timestamp logo.
3
3
"""
4
+ from __future__ import annotations
5
+
4
6
import warnings
7
+ from typing import TYPE_CHECKING
5
8
6
9
from packaging .version import Version
7
10
from pygmt .clib import Session , __gmt_version__
8
11
from pygmt .helpers import build_arg_string , kwargs_to_strings
9
12
13
+ if TYPE_CHECKING :
14
+ from collections .abc import Sequence
15
+
16
+
10
17
__doctest_skip__ = ["timestamp" ]
11
18
12
19
13
20
@kwargs_to_strings (offset = "sequence" )
14
21
def timestamp (
15
22
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 :
23
30
r"""
24
31
Plot the GMT timestamp logo.
25
32
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.
32
38
33
39
Parameters
34
40
----------
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
40
46
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).
63
67
64
68
Examples
65
69
--------
@@ -79,7 +83,7 @@ def timestamp(
79
83
self ._preprocess ()
80
84
81
85
# Build the options passed to the "plot" module
82
- kwdict = {"T" : True , "U" : "" }
86
+ kwdict : dict = {"T" : True , "U" : "" }
83
87
if label is not None :
84
88
kwdict ["U" ] += f"{ label } "
85
89
kwdict ["U" ] += f"+j{ justification } "
0 commit comments