Skip to content

Commit aad50f8

Browse files
committed
Figure.timestamp: Improve documentation and gallery example
1 parent 5fd85dd commit aad50f8

3 files changed

Lines changed: 30 additions & 20 deletions

File tree

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
"""
22
Timestamp
33
---------
4-
The :meth:`pygmt.Figure.timestamp` method can draw the
5-
GMT timestamp logo on the figure. The timestamp
6-
will always be shown relative to the bottom-left corner
7-
of the figure. By default, the ``offset`` and
8-
``justification`` parameters are set to
9-
``("-54p", "-54p")`` (x, y directions) and ``"BL"``
10-
(bottom-left), respectively.
4+
The :meth:`pygmt.Figure.timestamp` method can draw the GMT timestamp logo on
5+
the plot. The timestamp will always be shown relative to the bottom-left corner
6+
of the plot. By default, the ``offset`` and ``justification`` parameters are
7+
set to ``("-54p", "-54p")`` (x, y directions) and ``"BL"`` (bottom-left),
8+
respectively.
119
"""
12-
1310
# sphinx_gallery_thumbnail_number = 2
1411

12+
import os
13+
1514
import pygmt
1615

1716
fig = pygmt.Figure()
@@ -24,12 +23,14 @@
2423
# label font can be defined via the ``font`` parameter and the timestamp string
2524
# format via ``timefmt``.
2625

26+
os.environ["TZ"] = "Pacific/Honolulu" # optionally set the time zone
27+
2728
fig = pygmt.Figure()
2829
fig.coast(region="d", projection="H10c", land="black", water="cornsilk", frame="afg")
2930
fig.timestamp(
3031
label="Powered by PyGMT",
3132
justification="TL",
3233
font="Times-Bold",
33-
timefmt="%Y-%m-%dT%H:%M",
34+
timefmt="%Y-%m-%dT%H:%M:%S%z",
3435
)
3536
fig.show()

pygmt/src/timestamp.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,38 @@ def timestamp(
2323
r"""
2424
Plot the GMT timestamp logo.
2525
26+
Add the GMT timestamp logo with an optional label at the bottom-left corner
27+
of a plot. The timestamp will be in the locale set by the environment
28+
variable **TZ** (generally local time) and its foramt is controlled by the
29+
parameter ``timefmt``. It can also be replaced with any custom text string
30+
using the ``text`` parameter.
31+
2632
Parameters
2733
----------
2834
text : None or str
2935
If ``None``, the current UNIX timestamp is shown in the GMT timestamp
30-
logo. Set this parameter to replace the UNIX timestamp with a
31-
custom text string instead. The text must be less than 64 characters.
36+
logo. Set this parameter to replace the UNIX timestamp with a custom
37+
text string instead. The text must be no longer than 64 characters.
3238
label : None or str
3339
The text string shown after the GMT timestamp logo.
3440
justification : str
35-
Justification of the timestamp. The *justification* is a two-character
41+
Justification of the timestamp box relative to the plot's bottom-left
42+
corner (i.e., the plot origin). The *justification* is a two-character
3643
code that is a combination of a horizontal (**L**\ (eft),
3744
**C**\ (enter), or **R**\ (ight)) and a vertical (**T**\ (op),
38-
**M**\ (iddle), or **B**\ (ottom)) code.
45+
**M**\ (iddle), or **B**\ (ottom)) code. For example,
46+
``justification="TL"`` means choosing the **T**\ op **L**\ eft point of
47+
the timestamp as the anchor point.
3948
offset : str or tuple
4049
*offset* or (*offset_x*, *offset_y*).
41-
Offset the anchor point of the timestamp by *offset_x* and *offset_y*.
42-
If a single value *offset* is given, *offset_y* = *offset_x* =
43-
*offset*.
50+
Offset the anchor point of the timestamp box by *offset_x* and
51+
*offset_y*. If a single value *offset* is given, *offset_y* =
52+
*offset_x* = *offset*.
4453
font : str
45-
Font of the timestamp and the optional label. The parameter can't
46-
change the font color for GMT<=6.4.0, only the font ID.
54+
Font of the timestamp and the optional label. Since the GMT logo has a
55+
fixed height, the font sizes are fixed to be 8-point for the timestamp
56+
and 7-point for the label. The parameter can't change the font color
57+
for GMT<=6.4.0, only the font style.
4758
timefmt : str
4859
Format string for the UNIX timestamp. The format string is parsed by
4960
the C function ``strftime``, so that virtually any text can be used

pygmt/tests/test_timestamp.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ def test_timestamp_text_truncated():
8686
"""
8787
Passing a text string longer than 64 characters raises a warning and the
8888
string will be truncated.
89-
90-
Requires GMT>=6.5.0.
9189
"""
9290
fig = Figure()
9391
with pytest.warns(expected_warning=RuntimeWarning) as record:

0 commit comments

Comments
 (0)