Skip to main content
Albero Academy

Dates on Axes

Plot time series with well-formatted, non-overlapping date ticks.

Styling & Themes7 min

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

datetime x-values just work
ax.plot(dates, values) # dates can be datetime objects or a DatetimeIndex
fig.autofmt_xdate() # rotate & align date labels automatically

Formatting ticks

control the date format
import matplotlib.dates as mdates
ax.xaxis.set_major_locator(mdates.MonthLocator()) # a tick per month
ax.xaxis.set_major_formatter(mdates.DateFormatter("%b %Y")) # "Jan 2026"

Key takeaways

  1. 01Matplotlib plots datetime x-values natively.
  2. 02fig.autofmt_xdate() rotates and aligns date labels to prevent overlap.
  3. 03matplotlib.dates locators set where date ticks go; formatters set how they read.
  4. 04Choose a tick frequency and format that suit the time span.

Finished this chapter?

Mark it complete to track your progress through Matplotlib.