-
Notifications
You must be signed in to change notification settings - Fork 235
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 6 commits
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 |
|---|---|---|
|
|
@@ -510,6 +510,7 @@ def _repr_html_(self): | |
| subplot, | ||
| ternary, | ||
| text, | ||
| timestamp, | ||
| velo, | ||
| wiggle, | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,100 @@ | ||||||||
| """ | ||||||||
| timestamp - Plot the GMT timestamp logo. | ||||||||
| """ | ||||||||
| from packaging.version import Version | ||||||||
| from pygmt.clib import Session | ||||||||
| from pygmt.exceptions import GMTInvalidInput | ||||||||
| from pygmt.helpers import build_arg_string, is_nonstr_iter | ||||||||
|
|
||||||||
| __doctest_skip__ = ["timestamp"] | ||||||||
|
|
||||||||
|
|
||||||||
| def timestamp( | ||||||||
| self, | ||||||||
| text=None, | ||||||||
| label=None, | ||||||||
| justification="BL", | ||||||||
| offset=("-54p", "-54p"), | ||||||||
| font="Helvetica", | ||||||||
| timefmt="%Y %b %d %H:%M:%S", | ||||||||
| ): | ||||||||
| """ | ||||||||
| Plot the GMT timestamp logo. | ||||||||
|
|
||||||||
| Parameters | ||||||||
| ---------- | ||||||||
| text : None or str | ||||||||
| If ``None``, the current UNIX time stamp is shown in the GMT timestamp | ||||||||
yvonnefroehlich marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
seisman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||
| logo. Setting this parameter to replace the UNIX time stamp with a | ||||||||
| custom text string instead. The text must be less than 64 characters. | ||||||||
seisman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||
| *Requires GMT>=6.5.0*. | ||||||||
|
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. I'm still unsure what's the best way to document features that require new GMT versions.
Member
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. Hm. Is there a similar situation for the Julia wrapper, which can serve as an orientation? |
||||||||
| label : None or str | ||||||||
| The text string shown after the GMT timestamp logo. | ||||||||
yvonnefroehlich marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| justification : str | ||||||||
| Justification of the timestamp. *justification* is a two-character code | ||||||||
yvonnefroehlich marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
seisman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||
| 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 tuple | ||||||||
| *offset* or (*offset_x*, *offset_y*). | ||||||||
| Offset the anchor point of the timestamp by *offset_x* and *offset_y*. | ||||||||
yvonnefroehlich marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| If a single value *offset* is given, *offset_y*=*offset_x*=*offset*. | ||||||||
| font : str | ||||||||
| Font of the timestamp and the optional label. | ||||||||
yvonnefroehlich marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||
| For GMT<=6.4.0, the parameter can only change the font style. | ||||||||
| For GMT>=6.5.0, the parameter can change the font style and font color. | ||||||||
| timefmt : str | ||||||||
| Format of the time information in the UNIX time stamp. This format is | ||||||||
seisman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||
| parsed by the C function ``strftime``, so that virtually any text can | ||||||||
| be used (even not containing any time information). | ||||||||
|
|
||||||||
| Examples | ||||||||
| -------- | ||||||||
| >>> # Plot the GMT timestamp logo. | ||||||||
yvonnefroehlich marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| >>> import pygmt | ||||||||
| >>> fig = pygmt.Figure() | ||||||||
| >>> fig.timestamp() | ||||||||
| >>> fig.show() | ||||||||
| <IPython.core.display.Image object> | ||||||||
|
|
||||||||
| >>> # Plot the GMT timestamp logo with a custom label. | ||||||||
yvonnefroehlich marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| >>> fig = pygmt.Figure() | ||||||||
| >>> fig.timestamp(label="Powered by PyGMT") | ||||||||
| >>> fig.show() | ||||||||
| <IPython.core.display.Image object> | ||||||||
| """ | ||||||||
| self._preprocess() # pylint: disable=protected-access | ||||||||
|
|
||||||||
| # Build the options passed to the "plot" module | ||||||||
| kwdict = dict(T=True, U="") | ||||||||
| if label is not None: | ||||||||
| kwdict["U"] += f"{label}" | ||||||||
| kwdict["U"] += f"+j{justification}" | ||||||||
|
|
||||||||
| # Deal with compatibility with different GMT versions | ||||||||
| with Session() as lib: | ||||||||
| gmt_version = lib.info["version"] | ||||||||
|
|
||||||||
| if is_nonstr_iter(offset): # given a tuple | ||||||||
| kwdict["U"] += "+o" + "/".join(f"{item}" for item in offset) | ||||||||
| else: # given a single value | ||||||||
| if "/" not in offset and Version(gmt_version) <= Version("6.4.0"): | ||||||||
| # Giving a single offset doesn't work in GMT <= 6.4.0. | ||||||||
| # See https://github.com/GenericMappingTools/gmt/issues/7107. | ||||||||
| kwdict["U"] += f"+o{offset}/{offset}" | ||||||||
| else: | ||||||||
| kwdict["U"] += f"+o{offset}" | ||||||||
|
|
||||||||
| # The +t modifier was added in GMT 6.5.0. | ||||||||
| # See https://github.com/GenericMappingTools/gmt/pull/7127. | ||||||||
| if text is not None: | ||||||||
| if Version(gmt_version) <= Version("6.4.0"): | ||||||||
| raise GMTInvalidInput("The parameter 'text' requires GMT>=6.5.0.") | ||||||||
| kwdict["U"] += f"+t{text}" | ||||||||
|
|
||||||||
| with Session() as lib: | ||||||||
| lib.call_module( | ||||||||
| module="plot", | ||||||||
| args=build_arg_string(kwdict) | ||||||||
| + f" --FONT_LOGO={font} --FORMAT_TIME_STAMP={timefmt}", | ||||||||
|
||||||||
| _keywords = [ | |
| "COLOR_BACKGROUND", | |
| "COLOR_FOREGROUND", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, point 1 seems ok, but I'm not sure about point 2. I'd prefer to keep the three parameters in the list, because even if you remove it, you're only removing the autocompletion, but users can still manually set those parameters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Point 1 was implemented in PR #2324
Uh oh!
There was an error while loading. Please reload this page.