I'm trying to set the tick frequency on an xarray line plot. I managed to set the limits but I can't get the ticklocator to work. This should work similar to pandas.
import cftime
import xarray
fig=plt.figure()
ax0=plt.subplot(111)
xr_2d_data.plot(ax=ax0)
xmin = cftime.num2date(0*365, 'days since 0000-01-01 00:00:00', calendar='noleap')
xmax = cftime.num2date(1000*365, 'days since 0000-01-01 00:00:00', calendar='noleap')
ax0.set_xlim(xmin, xmax)
The above works, but if I try to set a locator , it does not work e.g.
import matplotlib.dates as mdates
ax0.xaxis.set_major_locator(mdates.YearLocator(100, month=1, day=1))
ax0.xaxis.set_major_formatter(mdates.DateFormatter('%Y'))