-
Notifications
You must be signed in to change notification settings - Fork 245
Add Figure.timestamp to plot the GMT timestamp logo #2208
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
Changes from 1 commit
c8206ec
2096760
e0bb6bb
4d6d777
fffe3cd
54f4307
fe8eeac
97574ac
1e8de17
79460fb
7031448
7ad112c
b057ad8
f92d272
cecf6de
7dd74d7
06049a6
876d963
752273e
f6795a9
9eba2a9
92c285a
776981b
c771183
386882e
e3580e7
41f5419
4def360
bc64e8c
78c2307
e6248c2
d989b22
960508f
16c0368
98b6762
b8a7fbb
688f6b0
6e168e1
5857866
01a3cbb
4fa2e72
0c07a48
e4bd94c
0079643
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -523,6 +523,7 @@ def _repr_html_(self): | |
| subplot, | ||
| ternary, | ||
| text, | ||
| timestamp, | ||
| velo, | ||
| wiggle, | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| """ | ||
| timestamp - Plot the GMT timestamp logo. | ||
| """ | ||
| from packaging.version import Version | ||
| from pygmt.clib import Session | ||
| from pygmt.helpers import build_arg_string, is_nonstr_iter | ||
|
|
||
| __doctest_skip__ = ["timestamp"] | ||
|
|
||
|
|
||
| def timestamp( | ||
| self, label=None, justification="BL", offset=("-54p", "-54p"), font="Helvetica" | ||
| ): | ||
| """ | ||
| Plot the GMT timestamp logo. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| label : str | ||
| The text string shown after the GMT timestamp logo. | ||
|
yvonnefroehlich marked this conversation as resolved.
|
||
| justification : str | ||
| Justification of the timestamp. *justification* is a two-character code | ||
|
yvonnefroehlich marked this conversation as resolved.
Outdated
seisman marked this conversation as resolved.
Outdated
|
||
| 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 | ||
| (*offset_x*, *offset_y*) or *offset*. | ||
| Offset the anchor point of the timestamp by *offset_x* and *offset_y*. | ||
|
yvonnefroehlich marked this conversation as resolved.
|
||
| If a single value *offset* is given, *offset_y*=*offset_x*=*offset*. | ||
| font : str | ||
| Font name or font number of the timestamp and the optional label . | ||
|
|
||
| Examples | ||
| -------- | ||
| >>> # Plot the GMT timestamp logo. | ||
|
yvonnefroehlich marked this conversation as resolved.
|
||
| >>> import pygmt | ||
| >>> fig = pygmt.Figure() | ||
| >>> fig.timestamp() | ||
| >>> fig.show() | ||
|
|
||
| >>> # Plot the GMT timestamp logo with a custom label. | ||
|
yvonnefroehlich marked this conversation as resolved.
|
||
| >>> 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}" | ||
| kwdict["U"] = f"{label}+j{justification}" | ||
|
|
||
| if is_nonstr_iter(offset): # given a list | ||
| kwdict["U"] += "+o" + "/".join(f"{item}" for item in offset) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please note that we can't use decorator
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Related issue report at #2361. |
||
| else: | ||
| kwdict["U"] += f"+o{offset}" | ||
| if "/" not in offset: | ||
| # Giving a single offset doesn't work in GMT <= 6.4.0. | ||
| # See https://github.com/GenericMappingTools/gmt/issues/7107. | ||
| 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=build_arg_string(kwdict) + f" --FONT_LOGO={font}" | ||
| ) | ||
Uh oh!
There was an error while loading. Please reload this page.