Skip to content

Enable plotting of now calendar-aware cftime.datetime objects #75

@spencerkclark

Description

@spencerkclark

✨ Feature Request

In cftime version 1.3.0 cftime.datetime objects are now calendar-aware. Eventually this will obviate the need for calendar-specific subclasses, like cftime.DatetimeNoLeap. nc-time-axis currently does not register cftime.datetime objects in matplotlib's units registry, so matplotlib does not attempt to convert them. It would be great if -- similar to the subclasses -- we could also directly plot the new calendar-aware base class using nc-time-axis.

Motivation

E.g. while we can currently do:

import random

import cftime
import matplotlib.pyplot as plt
import nc_time_axis

dt = [cftime.DatetimeNoLeap(2017, 2, day) for day in range(1, 28)]
temperatures = [round(random.uniform(0, 12), 3) for _ in range(len(dt))]
plt.plot(dt, temperatures)

It would be great if we could also do:

dt = [cftime.datetime(2017, 2, day, calendar="noleap") for day in range(1, 28)]
temperatures = [round(random.uniform(0, 12), 3) for _ in range(len(dt))]
plt.plot(dt, temperatures)

This currently results in an error, because matplotlib does not convert the dates.

Metadata

Metadata

Assignees

No one assigned

    Labels

    New: FeatureHighlight a new community raised "feature request" issue

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions