Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk3 min

Matplotlib Date Formatting: Replace plot_date and Convert Dates

Matplotlib 3.11 removed plot_date. Use plot for datetime data, then configure date locators and formatters or convert dates explicitly when numeric values are needed.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

In Matplotlib 3.11, plot_date has been removed. Plot Python datetime or NumPy datetime64 values directly with plot; Matplotlib handles date conversion and usually chooses date-aware ticks automatically. Use date2num or num2date only when you specifically need Matplotlib’s numeric date representation.

Replace plot_date with plot

plot_date was discouraged starting in Matplotlib 3.5, deprecated in 3.9, and removed in 3.11. The Matplotlib 3.11.0 API changes direct users to plot datetime-like data with plot instead. Matplotlib 3.11.0 API changes

As an Amazon Associate I earn from qualifying purchases.

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.plot(dates, values, marker="o")
plt.show()

Here, dates can contain Python datetime objects or NumPy datetime64 values. Matplotlib’s date converter handles them, so ordinary date plotting does not require a preliminary conversion to floats. Plotting dates and strings

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Format date labels and control tick spacing

A locator chooses where ticks go; a formatter chooses the text displayed at those ticks. Configure each separately when Matplotlib’s automatic choices do not suit the chart.

import matplotlib.dates as mdates

ax.xaxis.set_major_locator(mdates.DayLocator(interval=1))
ax.xaxis.set_major_formatter(mdates.DateFormatter("%Y-%m-%d"))
fig.autofmt_xdate()

DayLocator(interval=1) requests a tick each day, while DateFormatter("%Y-%m-%d") displays labels such as 2026-10-10. Other strftime-style formats include "%b %d" for abbreviated month and day. The actual tick schedule can depend on the date range and locator; consult the date plotting guide for locator and formatter examples.

When labels overlap

  • Reduce the number of ticks by increasing the locator interval or selecting a locator appropriate to the time span.
  • Rotate labels with fig.autofmt_xdate() or ax.tick_params(axis="x", rotation=70).
  • For spans with repeated year or month text, use Matplotlib’s concise date formatter to reduce redundant parts of labels. Plotting dates and strings

A date locator is preferable to manually assigning a string to every tick when the axis represents a changing date range: locator positions remain date-aware as the plotted range changes.

Convert dates to and from Matplotlib date numbers

Matplotlib date numbers are floating-point values measured in days from an epoch, not Unix timestamps in seconds. The default epoch is 1970-01-01T00:00:00. date2num converts dates to Matplotlib numbers; num2date converts numbers back to date values.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import matplotlib.dates as mdates

number = mdates.date2num(dates[0])
recovered_date = mdates.num2date(number)

Use these conversions when another calculation or interface specifically needs numeric Matplotlib date values. For plotting date-like inputs, direct use of ax.plot(dates, values) is simpler.

Plot numeric date values or set a timezone

If x values are already numeric Matplotlib date numbers, tell the axis to interpret them as dates before plotting. Otherwise, plain floats may be treated as ordinary numeric coordinates.

ax.xaxis.axis_date()
ax.plot(date_numbers, values)

Matplotlib’s 3.11 API changes also point to axis_date when configuring a date axis or timezone. A numeric date value of zero represents the configured epoch when the axis is using date units. Matplotlib 3.11.0 API changes

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Check precision for fine-grained timestamps

Floating-point date values have finite precision, and the precision guidance notes that it depends on how close dates are to the epoch. Most daily and hourly charts do not need an epoch change. If microsecond precision is important for modern dates, see Matplotlib’s date precision and epochs guide.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If you change the epoch, do it before any date operations. Changing it after date conversion or plotting has begun raises a RuntimeError. The default epoch and its configuration are documented in the rcParams reference.

Troubleshoot unexpected date axes

  • ImportError or missing function: If code calls plot_date under Matplotlib 3.11 or later, replace it with plot and pass date-like values directly.
  • Unexpected numeric tick labels: Confirm the x values are date-like, or call ax.xaxis.axis_date() before plotting numeric Matplotlib date values.
  • Overlapping labels: Change the locator interval, use a different date locator, or rotate labels.
  • Insufficient microsecond precision: Check the epoch guidance and configure the epoch before performing date operations.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.