I draw a figure where the default format is displayed as:

I would like to change it so that monthly ticks appear every 1 month, but save a year. My current attempt:
years = mdates.YearLocator() months = mdates.MonthLocator() monthsFmt = mdates.DateFormatter('%b-%y') dts = s.index.to_pydatetime() fig = plt.figure(); ax = fig.add_subplot(111) ax.plot(dts, s) ax.xaxis.set_major_locator(months) ax.xaxis.set_major_formatter(monthsFmt)
but this does not give the correct result:

How exactly do I need to change it so that it appears as the first, but with months of ticks appear every month?
source share