Formatting axes' tick date labels using formatters

Formatting of axes' labels whose underlying data type is datetime is done using locators and formatters. Locators control the position of the ticks and formatters control the formatting of the labels.

matplotlib provides several classes in maptplotlib.dates to help facilitate the process:

  • MinuteLocator, HourLocator, DayLocator, WeekdayLocator, MonthLocator, and YearLocator
  • These are specific locators coded to determine where the ticks for each type of date field will be found on the axis
  • DateFormatter
  • This is a class that can be used to format date objects into labels on the axis

The default locator and formatter are AutoDateLocator and AutoDateFormatter. These can be changed by providing ...

Get Learning pandas - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.