Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
seisman committed Dec 2, 2022
1 parent 7a70dc0 commit bf29f17
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions pygmt/src/timestamp.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""
timestamp - Plot the GMT timestamp logo.
"""
from packaging.version import Version
from pygmt.clib import Session
from pygmt.helpers import is_nonstr_iter
from pygmt.helpers import build_arg_string, is_nonstr_iter

__doctest_skip__ = ["timestamp"]

Expand All @@ -22,36 +23,48 @@ def timestamp(
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.
offset : str or list of str
offset : str or list
(*offset_x*, *offset_y*) or *offset*.
Offset the anchor point for the timestamp by *offset_x* and *offset_y*.
Offset the anchor point of the timestamp by *offset_x* and *offset_y*.
If a single value *offset* is given, *offset_y*=*offset_x*=*offset*.
font : str or int
font : str
Font name or font number of the timestamp and the optional label .
Example
-------
Examples
--------
>>> # Plot the GMT timestamp logo.
>>> import pygmt
>>> fig = pygmt.Figure()
>>> fig.timestamp()
>>> fig.show()
>>> # Plot the GMT timestamp logo with a custom label.
>>> fig = pygmt.Figure()
>>> fig.timestamp(label="Powered by PyGMT")
>>> fig.show()
"""
self._preprocess() # pylint: disable=protected-access

kwdict = {}
kwdict["T"] = True # pass the -T option to the plot module
kwdict["U"] = True

# build the argument for the -U option
label = "" if label is None else f"{label}"
uarg = f"{label}+j{justification}"
kwdict["U"] = f"{label}+j{justification}"

if is_nonstr_iter(offset):
uarg += "+o" + "/".join(f"{item}" for item in offset)
if is_nonstr_iter(offset): # given a list
kwdict["U"] += "+o" + "/".join(f"{item}" for item in offset)
else:
kwdict["U"] += f"+o{offset}"
if "/" not in offset:
# only one offset is given
# Workaround for an upstream bug which will be fixed in GMT 6.5.0.
# Giving a single offset doesn't work in GMT <= 6.4.0.
# See https://github.com/GenericMappingTools/gmt/issues/7107.
uarg += f"+o{offset}/{offset}"
else:
uarg += f"+o{offset}"
with Session() as lib:
if Version(lib.info["version"]) < Version("6.5.0"):
kwdict["U"] += "/{offset}"

with Session() as lib:
lib.call_module(module="plot", args=f"-U{uarg} -T --FONT_LOGO={font}")
lib.call_module(
module="plot", args=build_arg_string(kwdict) + f" --FONT_LOGO={font}"
)

0 comments on commit bf29f17

Please sign in to comment.