I'm using Matplotlib to plot temperatures versus a list of datetimes from May to Nov 2021. ConciseDateFormatter is used to format the x-axis dates.
When I generate a plot, the months show up as abbreviated month strings, which I want, but the year doesn't show up anywhere on the x-axis labels. I want the year of my date strings "2021" to show on the x-axis. Click here to see the my plot
The Matplotlib documentation says that there should be an offset string on the right side of the x-axis, which should completely specify the date when combined with tick labels, so shouldn't the year appear?
Is this a bug or an issue with my code? (my code is below)
From checking other posts, the year shows up in the x-axis when the dates cross the zero-mark of a year (January), but since my data is Feb to Sept, that functionality doesn't work for me.
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from datetime import datetime, timedelta
#create time array
initial = datetime(2021,2,14,0,0,0)
time_array = [initial + timedelta(days=x) for x in range(1,200)]
#create data array
data = [-x**2/20000 for x in range(1,200)]
#plot data
fig,ax = plt.subplots()
ax.plot(time_array,data)
locator = mdates.AutoDateLocator()
formatter = mdates.ConciseDateFormatter(locator)
ax.grid(True)
ax.set_ylabel("Temperature ($\degree$C)")
ax.xaxis.set_major_locator(locator)
ax.xaxis.set_major_formatter(formatter)
fig.autofmt_xdate() #automatically makes the x-labels rotate