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

Figure.timestamp: Deprecate parameter 'justification' to 'justify' (remove in v0.13.0) #3002

Merged
merged 8 commits into from
Jan 19, 2024
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
16 changes: 7 additions & 9 deletions examples/gallery/embellishments/timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
Timestamp
=========

The :meth:`pygmt.Figure.timestamp` method can draw the GMT timestamp logo on
the plot. The timestamp will always be shown relative to the bottom-left corner
of the plot. By default, the ``offset`` and ``justification`` parameters are
set to ``("-54p", "-54p")`` (x, y directions) and ``"BL"`` (bottom-left),
respectively.
The :meth:`pygmt.Figure.timestamp` method can draw the GMT timestamp logo on the plot.
The timestamp will always be shown relative to the bottom-left corner of the plot. By
default, the ``offset`` and ``justify`` parameters are set to ``("-54p", "-54p")``
(x, y directions) and ``"BL"`` (bottom-left), respectively.
"""

# %%
Expand All @@ -20,17 +19,16 @@
fig.show()

# %%
# Additionally, a custom label can be added via the ``label`` parameter. The
# font can be defined via the ``font`` parameter and the timestamp string
# format via ``timefmt``.
# Additionally, a custom label can be added via the ``label`` parameter. The font can be
# defined via the ``font`` parameter and the timestamp string format via ``timefmt``.

os.environ["TZ"] = "Pacific/Honolulu" # optionally set the time zone

fig = pygmt.Figure()
fig.coast(region="d", projection="H10c", land="black", water="cornsilk", frame="afg")
fig.timestamp(
label="Powered by PyGMT",
justification="TL",
justify="TL",
font="Times-Bold",
timefmt="%Y-%m-%dT%H:%M:%S%z",
)
Expand Down
21 changes: 11 additions & 10 deletions pygmt/src/timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from packaging.version import Version
from pygmt.clib import Session, __gmt_version__
from pygmt.helpers import build_arg_string, kwargs_to_strings
from pygmt.helpers import build_arg_string, deprecate_parameter, kwargs_to_strings

if TYPE_CHECKING:
from collections.abc import Sequence
Expand All @@ -17,16 +17,17 @@
__doctest_skip__ = ["timestamp"]


@deprecate_parameter("justification", "justify", "v0.11.0", remove_version="v0.13.0")
@kwargs_to_strings(offset="sequence")
def timestamp(
self,
text: str | None = None,
label: str | None = None,
justification: str = "BL",
justify: str = "BL",
offset: float | str | Sequence[float | str] = ("-54p", "-54p"),
font: str = "Helvetica,black",
timefmt: str = "%Y %b %d %H:%M:%S",
) -> None:
):
r"""
Plot the GMT timestamp logo.

Expand All @@ -44,13 +45,13 @@ def timestamp(
The text must be no longer than 64 characters.
label
The text string shown after the GMT timestamp logo.
justification
justify
Justification of the timestamp box relative to the plot's bottom-left corner
(i.e., the plot origin). The *justification* is a two-character code that is a
combination of a horizontal (**L**\ (eft), **C**\ (enter), or **R**\ (ight)) and
a vertical (**T**\ (op), **M**\ (iddle), or **B**\ (ottom)) code. For example,
``justification="TL"`` means choosing the **T**\ op **L**\ eft point of the
timestamp as the anchor point.
(i.e., the plot origin). Give a two-character code that is a combination of a
horizontal (**L**\ (eft), **C**\ (enter), or **R**\ (ight)) and a vertical
(**T**\ (op), **M**\ (iddle), or **B**\ (ottom)) code. For example,
``justify="TL"`` means choosing the **T**\ op **L**\ eft point of the timestamp
as the anchor point.
offset
*offset* or (*offset_x*, *offset_y*).
Offset the anchor point of the timestamp box by *offset_x* and *offset_y*. If a
Expand Down Expand Up @@ -86,7 +87,7 @@ def timestamp(
kwdict: dict = {"T": True, "U": ""}
if label is not None:
kwdict["U"] += f"{label}"
kwdict["U"] += f"+j{justification}"
kwdict["U"] += f"+j{justify}"

if Version(__gmt_version__) <= Version("6.4.0") and "/" not in str(offset):
# Giving a single offset doesn't work in GMT <= 6.4.0.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
outs:
- md5: fcf1511052ece6b0e2ed97b6ae5af772
size: 8828
path: test_timestamp_justification.png
path: test_timestamp_justify.png
hash: md5
6 changes: 3 additions & 3 deletions pygmt/tests/test_timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ def test_timestamp_label(faketime):


@pytest.mark.mpl_image_compare
def test_timestamp_justification():
def test_timestamp_justify():
"""
Check if the "justification" parameter works.
Check if the "justify" parameter works.

Only a subset of justification codes are tested to avoid overlapping timestamps.
"""
fig = Figure()
fig.basemap(projection="X10c/5c", region=[0, 10, 0, 5], frame=0)
for just in ["BL", "BR", "TL", "TR"]:
fig.timestamp(justification=just, timefmt=just)
fig.timestamp(justify=just, timefmt=just)
return fig


Expand Down
Loading