I am able to create a plot with the name of the month when I have 365 data points with the following code:
y = np.random.normal(size=365)
x = np.array(range(len(y)))
plt.plot(x, y)
plt.xlabel('Month')
locator = mdates.MonthLocator()
fmt = mdates.DateFormatter('%b')
X = plt.gca().xaxis
X.set_major_locator(locator)
X.set_major_formatter(fmt)
Here is the result, which is exactly what I'm looking for:
I would like to do the same thing but with only 12 data points (one for each month). If I just change the 365 to 12 (y = np.random.normal(size=12)
), it looks like this:
How can I get it to show all the months in the x axis as in the first graph?