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
Matplotlib counts years from zero but UNIX since 1970. Therefore you got years of 48, 49 and etc. To avoid this behavior of matplotlib you have to get from your pandas datetime index date part and then use %Y
descriptor to get full years for major ticks:
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.date) # get dates
df = pd.DataFrame(s)
months = MonthLocator() # MonthLocator without args set ticks for every month
monthsFmt = DateFormatter("%b")
years = YearLocator(month=4, day=1)
yrsFmt = DateFormatter("\n%Y") # correct year descriptor
ax = df.plot()
ax.xaxis.set_minor_locator(months)
ax.xaxis.set_minor_formatter(monthsFmt)
for tick in ax.xaxis.get_minor_ticks():tick.label.set_fontsize(9)
ax.xaxis.set_major_locator(years)
ax.xaxis.set_major_formatter(yrsFmt)
plt.show()