Time series are everywhere, and Matplotlib understands dates natively — but the default tick labels often overlap or show too much detail. A little formatting makes them clean.
Plotting dates
ax.plot(dates, values) # dates can be datetime objects or a DatetimeIndexfig.autofmt_xdate() # rotate & align date labels automatically
Formatting ticks
import matplotlib.dates as mdatesax.xaxis.set_major_locator(mdates.MonthLocator()) # a tick per monthax.xaxis.set_major_formatter(mdates.DateFormatter("%b %Y")) # "Jan 2026"
Key takeaways
- 01Matplotlib plots datetime x-values natively.
- 02fig.autofmt_xdate() rotates and aligns date labels to prevent overlap.
- 03matplotlib.dates locators set where date ticks go; formatters set how they read.
- 04Choose a tick frequency and format that suit the time span.
