I'm plotting a figure where the default format shows up as:
I would like to modify it so that the month ticks show up every 1 month but keep the year. My current attempt is this:
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 it's not producing the right result:
How exactly do I need to modify it so that it shows up like the first but with the months ticks appear every month?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…