question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

datetime locator doesn't work with cftime

See original GitHub issue

Code sample, a copy-pastable example if possible

import proplot as plot
import numpy as np
import xarray as xr

times = xr.cftime_range('1990', '2000', freq='M')
data = xr.DataArray(np.random.rand(len(times)),
    dims=['time'],
    coords=[times])

f, ax = plot.subplots(aspect=2)

ax.plot(data.time, data)

# ax.format(xlocator='year')
# ax.format(xformatter='concise')

Actual result vs. expected result

The x datetime axis appears by default (with the comments included above), but when using ax.format(xlocator='year') or any locator, the xticks and labeling completely disappear.

When using any formatter (e.g. xformatter='concise') it breaks with the following error:

ValueError: Cannot convert -3652 to a date.  This often happens if non-datetime values are passed to an axis that expects datetime objects.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
bradyrxcommented, Mar 23, 2020

I’m reopening this based on our discussion at https://github.com/SciTools/nc-time-axis/issues/41. It looks like nc-time-axis is sort of a dead repo. This is on the longer-term list for proplot developments.

0reactions
lukelbdcommented, May 19, 2020

After the reorganization, the cftime additions should go in ticker.py. This isn’t a priority for me right now, but this is an ideal issue for collaboration if someone else wants to try

Read more comments on GitHub >

github_iconTop Results From Across the Web

matplotlib.pyplot plot_date function breaks on cftime.datetime ...
Found the answer myself, from version 1.1.0 the num2date function in the cftime package changed its default behaviour to return cftime ...
Read more >
Using Python datetime to Work With Dates and Times
Have you ever wondered about working with dates and times in Python? In this tutorial, you'll learn all about the built-in Python datetime...
Read more >
Fixing common date annoyances - Matplotlib
To fix the first problem, we can use Figure.autofmt_xdate and to fix the second problem we can use the ax.fmt_xdata attribute which can...
Read more >
xarray.CFTimeIndex — xarray 0.10.4 documentation
Custom Index for working with CF calendars and dates. All elements of a CFTimeIndex must be cftime.datetime objects. __init__ ($self, /, *args, **kwargs)¶....
Read more >
API — cftime 1.0 documentation
dates: A datetime object or a sequence of datetime objects. The datetime objects should not include a time-zone offset. nctime: A netCDF time...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found