import cftime
import matplotlib.pyplot as plt
import numpy as np
import xarray as xr
from nc_time_axis import CalendarDateTime
%matplotlib inline
nc_time_axis
and dates generated by cftime_range
¶dates = xr.cftime_range('0001', periods=24, freq='MS', calendar='noleap')
plt.plot([CalendarDateTime(date, date.calendar) for date in dates], range(24))
[<matplotlib.lines.Line2D at 0x10e8c5fd0>]
The difference is subtle; here is a minimal example where it matters.
gregorian_dates = [cftime.DatetimeGregorian(2000, 2, 28),
cftime.DatetimeGregorian(2000, 3, 1),
cftime.DatetimeGregorian(2000, 3, 2)]
noleap_dates = [cftime.DatetimeNoLeap(2000, 2, 28),
cftime.DatetimeNoLeap(2000, 3, 1),
cftime.DatetimeNoLeap(2000, 3, 2)]
fig, axes = plt.subplots(1, 2, sharey=True, figsize=(8, 2))
ax1, ax2 = axes
ax1.plot([CalendarDateTime(date, date.calendar) for date in gregorian_dates], range(3), marker='o')
ax2.plot([CalendarDateTime(date, date.calendar) for date in noleap_dates], range(3), marker='o')
for ax in axes:
for tick in ax.get_xticklabels():
tick.set_rotation(45)
ax1.set_title('gregorian')
ax2.set_title('noleap')
Text(0.5,1,'noleap')