I would like to show each month abbreviation, as well as the year on the year.
I am quite close. The issue I am currently having is that the years are incorrect. I have figured out that this is a issue between numpy.datetime64 (the datetime index is in this format), and python datetime which is used the 1970 epoch. The two years shown on the chart should be 2017 and 2018 but they show 48 and 49.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.dates import MonthLocator, WeekdayLocator, DateFormatter, YearLocator
indx = pd.date_range('2017-04-01', '2019-01-01')
s = pd.Series(np.random.randn(len(indx)), index=indx)
df = pd.DataFrame(s)
ax = df.plot()
months = MonthLocator(range(1, 13), bymonthday=1, interval=1)
monthsFmt = DateFormatter("%b")
years = YearLocator(1, month=4, day=1)
yrsFmt = DateFormatter("\n %y")
ax.xaxis.set_major_locator(years)
ax.xaxis.set_major_formatter(yrsFmt)
ax.xaxis.set_minor_locator(months)
ax.xaxis.set_minor_formatter(monthsFmt)
plt.show()
How do I show the right years here?


