-
Notifications
You must be signed in to change notification settings - Fork 228
Create gallery example for datetime inputs #779
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
95c8f63
Create gallery example for datetime inputs
michaelgrund 4e19589
[format-command] fixes
actions-bot 87c8128
Update examples/gallery/plot/datetime-inputs.py
michaelgrund 72ae903
Update datetime-inputs.py
michaelgrund c34d11a
Update datetime-inputs.py
michaelgrund d626b47
Update examples/gallery/plot/datetime-inputs.py
michaelgrund af9ad23
Update examples/gallery/plot/datetime-inputs.py
michaelgrund 42b7ad5
Update examples/gallery/plot/datetime-inputs.py
michaelgrund 7f2103e
[format-command] fixes
actions-bot 74d38af
Merge branch 'master' into patch-2
seisman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
""" | ||
Datetime inputs | ||
--------------- | ||
|
||
The :meth:`pygmt.Figure.plot` method can plot datetime inputs of individual types: | ||
|
||
- numpy.datetime64: for available options see https://numpy.org/doc/stable/reference/arrays.datetime.html | ||
seisman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- :class:`pandas.DatetimeIndex` | ||
- :class:`xarray.DataArray`: datetimes included in a *xarray.DataArray* | ||
- raw datetime strings in ISO format (e.g. ``["YYYY-MM-DD", "YYYY-MM-DDTHH", "YYYY-MM-DDTHH:MM:SS"]``) | ||
michaelgrund marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- Python built-in :class:`datetime.datetime` and :class:`datetime.date` | ||
|
||
We can pass datetime inputs based on one of the types listed above directly to the ``x`` and ``y`` options. | ||
michaelgrund marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
The ``region`` argument has to include the :math:`x` and :math:`y` axis limits as *str* in the form | ||
``"date_min/data_max/ymin/ymax"``. | ||
|
||
""" | ||
|
||
import datetime | ||
|
||
import numpy as np | ||
import pandas as pd | ||
import pygmt | ||
import xarray as xr | ||
|
||
fig = pygmt.Figure() | ||
|
||
# create a basemap with limits of 2010-01-01 to 2020-06-01 on the x axis and | ||
# 0 to 10 on the y axis | ||
fig.basemap(projection="X15c/5c", region="2010-01-01/2020-06-01/0/10", frame=True) | ||
michaelgrund marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# numpy.datetime64 types | ||
x = np.array(["2010-06-01", "2011-06-01T12", "2012-01-01T12:34:56"], dtype="datetime64") | ||
y = [1, 2, 3] | ||
fig.plot(x, y, style="c0.4c", pen="1p", color="red3") | ||
|
||
# pandas.DatetimeIndex | ||
x = pd.date_range("2013", periods=3, freq="YS") | ||
y = [4, 5, 6] | ||
fig.plot(x, y, style="t0.4c", pen="1p", color="gold") | ||
|
||
# xarray.DataArray | ||
x = xr.DataArray(data=pd.date_range(start="2015-03", periods=3, freq="QS")) | ||
y = [7.5, 6, 4.5] | ||
fig.plot(x, y, style="s0.4c", pen="1p") | ||
|
||
# raw datetime strings | ||
x = ["2016-02-01", "2016-06-04T14", "2016-10-04T00:00:15"] | ||
y = [7, 8, 9] | ||
fig.plot(x, y, style="a0.4c", pen="1p", color="dodgerblue") | ||
|
||
# the Python built-in datetime and date | ||
x = [datetime.date(2018, 1, 1), datetime.datetime(2019, 6, 1, 20, 5, 45)] | ||
y = [6.5, 4.5] | ||
fig.plot(x, y, style="i0.4c", pen="1p", color="seagreen") | ||
|
||
fig.show() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.