I would like to add monthly ticks to this plot - and it is currently showing ticks of 2015 and 2016 where i would like it to show Jan, Feb...Dec, Jan.
The index of
Tough to try without your exact data, but I think you're simply missing a call to set_major_formatter
.
import datetime
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
# Generate some random date-time data
numdays = 500
base = datetime.datetime.today()
date_list = [base - datetime.timedelta(days=x) for x in range(0, numdays)]
y = np.random.rand(numdays)
# Set the locator
locator = mdates.MonthLocator() # every month
# Specify the format - %b gives us Jan, Feb...
fmt = mdates.DateFormatter('%b')
plt.plot(date_list,y)
X = plt.gca().xaxis
X.set_major_locator(locator)
# Specify formatter
X.set_major_formatter(fmt)
plt.show()