Skip to content

Support datetime types in region argument #561

@weiji14

Description

@weiji14

Description of the desired feature

Support passing in 'datetime' like inputs into the 'region' or '-R' argument in plot.

  • The region argument doesn't work with numpy datetime64 objects, have to convert to a string using np.datetime_as_string in order to set the map frame bounds.

The decorator kwargs_to_strings convert the list [w, e, s, n] to a string w/e/s/n. We need to convert datetime64 object to string internally, but it's not ideal to do the conversion in the decorator. I don't have a good solution now.

Originally posted by @seisman in #464 (comment)

Minimal working example:

import pandas as pd
import pygmt

fig = pygmt.Figure()
fig.plot(x=["2020-06-30"], y=[1], region=[pd.Timestamp("2020-01-01"), pd.Timestamp("2020-12-31"), 0, 2])
fig.show()

The error message is:

GMTCLibError: Module 'plot' failed with status code 71:
plot [ERROR]: Option -R parsing failure. Correct syntax:
plot [ERROR]: Offending option -R2020-01-01

This workaround does work, but it's cumbersome:

fig = pygmt.Figure()
fig.plot(
    x=[pd.Timestamp("2020-06-30")],
    y=[1],
    region=[
        pd.Timestamp("2020-01-01").isoformat(),
        pd.Timestamp("2020-12-31").isoformat(),
        0,
        2,
    ],
    style="a10c",
    frame=True,
)
fig.show()

produces:

Expected plot with star in middle

Are you willing to help implement and maintain this feature? Yes, but where should this code logic go?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementImproving an existing feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions