Matplotlib plot_date: What It Did and What to Use Now

Copied an older chart script, ran it, and got an AttributeError on plot_date? Your code isn’t wrong so much as out of date, and the repair takes one line.

In this tutorial, we’ll cover what matplotlib plot_date used to do, reproduce the real error, and swap it for ax.plot() on real dates.

Quick answer: plot_date() was deprecated in Matplotlib 3.9 and removed in 3.11. Replace it with ax.plot() and pass "o" to keep the same round markers:

ax.plot(days, checkins, "o")   # was: ax.plot_date(days, checkins)

We ran every script below on Matplotlib 3.11.2 on Python 3.12.5, so each output block is copied from a real run.

What You Need Before You Start

You only need Python and Matplotlib, plus pandas for one step. If the import fails, our guide on how to install Matplotlib in Python sorts that out first. Run python -m pip show matplotlib to see which version you have.

Step 1: Create the Sample Check-In Data

We’ll use one dataset for the whole walk-through: 60 days of made-up check-ins at an Austin gym, starting March 2, 2026. Save this as gym_checkins.py, because the later scripts import it.

import random
from datetime import date, timedelta

random.seed(2026)
start = date(2026, 3, 2)
days = [start + timedelta(days=i) for i in range(60)]
checkins = [round(210 + i * 0.8 + random.gauss(0, 14)) for i in range(60)]

if __name__ == "__main__":
    print("Days:", len(days))
    print("First:", days[0], "check-ins:", checkins[0])
    print("Last: ", days[-1], "check-ins:", checkins[-1])

Output:

Days: 60
First: 2026-03-02 check-ins: 222
Last:  2026-04-30 check-ins: 264
Command Prompt output of gym_checkins.py showing 60 days from March 2 to April 30, 2026 with first and last check-in counts
The sample covers 60 days, from March 2 through April 30, 2026.

days holds Python date objects rather than text. That’s what makes the replacement work with no conversion.

Step 2: Understand What plot_date Did and See the Error

plot_date() was a thin convenience wrapper around plot(). Its signature was plot_date(x, y, fmt='o', tz=None, xdate=True, ydate=False), and it did just two jobs: draw round markers with no line, and flag an axis as dates.

It came from a time when you had to convert dates to numbers yourself. Modern plot() recognizes dates on its own, so the wrapper had nothing left to add. Here’s the old call on our check-in data:

import matplotlib
import matplotlib.pyplot as plt
from matplotlib.axes import Axes
from gym_checkins import days, checkins

print("Matplotlib", matplotlib.__version__)
print("Axes has plot_date:", hasattr(Axes, "plot_date"))
plt.plot_date(days, checkins)

Output (the error):

Matplotlib 3.11.2
Axes has plot_date: False
Traceback (most recent call last):
  File "C:\pyguides\plot_date_test.py", line 8, in <module>
    plt.plot_date(days, checkins)
    ^^^^^^^^^^^^^
AttributeError: module 'matplotlib.pyplot' has no attribute 'plot_date'
Command Prompt traceback showing Axes has plot_date False and AttributeError because matplotlib.pyplot has no attribute plot_date
On 3.11 the function no longer exists, on pyplot or on Axes.

Calling ax.plot_date() fails the same way, because the method itself is gone.

Step 3: Replace plot_date with ax.plot on Real Dates

Same check-ins, one change. The format string "o" gives you the markers-only look that plot_date() drew by default:

import matplotlib.pyplot as plt
from gym_checkins import days, checkins

fig, ax = plt.subplots(figsize=(7, 3.6), layout="constrained")
ax.plot(days, checkins, "o", markersize=4)
ax.set_title("Austin gym: daily check-ins, 2026")
ax.set_ylabel("Check-ins")
fig.autofmt_xdate()
print(type(ax.xaxis.get_major_locator()).__name__)
plt.show()

Output:

AutoDateLocator
Matplotlib plot window showing 60 days of Austin gym check-ins as round markers with automatic date ticks on the x axis
ax.plot() with "o" matches the old default chart.

AutoDateLocator in the output proves Matplotlib spotted the dates and built a date axis by itself. To control those ticks, see our walk-through on dates on the x axis and xticks.

The fig.autofmt_xdate() line tilts the date labels so 60 days of ticks don’t run into each other.

Step 4: Add a Connecting Line Between the Dates

Lots of old scripts passed linestyle='solid' to get a line through the markers. Those keyword arguments carry straight over to plot(). Same data, now connected:

import matplotlib.pyplot as plt
from gym_checkins import days, checkins

fig, ax = plt.subplots(figsize=(7, 3.6), layout="constrained")
ax.plot(days, checkins, marker="o", markersize=3, linestyle="-")
ax.set_title("Austin gym: daily check-ins, 2026")
fig.autofmt_xdate()
print(len(ax.lines), "line,", len(ax.lines[0].get_xdata()), "points")
plt.show()

Output:

1 line, 60 points
Matplotlib plot window showing Austin gym check-ins as a connected line with small round markers on a date axis
One line through all 60 points, with markers kept.

Drop the marker argument for a plain line. Dashes, dots and colors are covered in our post on line style and color on date charts.

Step 5: Convert date2num Floats with xaxis_date

This is the one case where deleting plot_date isn’t enough. If your x values are already numbers from date2num(), plot() can’t know they’re dates, so you must say so:

import matplotlib.dates as mdates
import matplotlib.pyplot as plt
from gym_checkins import days, checkins

nums = mdates.date2num(days)
print("First value:", float(nums[0]))

fig, ax = plt.subplots()
ax.plot(nums, checkins, "o")
print("Before:", type(ax.xaxis.get_major_locator()).__name__)

ax.xaxis_date()
print("After: ", type(ax.xaxis.get_major_locator()).__name__)

Output:

First value: 20514.0
Before: AutoLocator
After:  AutoDateLocator

The first value, 20514.0, counts days since January 1, 1970. xaxis_date() switches the axis from a plain number locator to a date locator. For more on converting values, see date formats and conversion in Matplotlib.

Step 6: Translate the ydate and tz Arguments

Two plot_date arguments need their own replacement. For ydate=True, just pass the real dates as the second argument. Here’s the first two weeks of check-ins with dates running up the y axis:

import matplotlib.pyplot as plt
from gym_checkins import days, checkins

fig, ax = plt.subplots(figsize=(7, 3.6), layout="constrained")
ax.plot(checkins[:14], days[:14], "o")
ax.set_xlabel("Check-ins")
print(type(ax.yaxis.get_major_locator()).__name__)
plt.show()

Output:

AutoDateLocator
Matplotlib plot window with check-in counts on the x axis and two weeks of March 2026 dates on the y axis
Real dates in the y position get a date axis automatically.

For tz=, call ax.xaxis_date(tz=...) and give your formatter the same zone. This small script stores times in UTC and labels them in Central time:

from datetime import datetime, timedelta, timezone
import matplotlib.dates as mdates
import matplotlib.pyplot as plt

start = datetime(2026, 3, 9, 13, tzinfo=timezone.utc)
hours = [start + timedelta(hours=i) for i in range(8)]
visits = [18, 31, 27, 22, 25, 29, 40, 46]

fig, ax = plt.subplots()
ax.plot(hours, visits, "o")
ax.xaxis_date(tz="America/Chicago")

fmt = mdates.DateFormatter("%b %d, %I:%M %p", tz="America/Chicago")
ax.xaxis.set_major_formatter(fmt)
print("Stored:", hours[0])
print("Shown: ", fmt(mdates.date2num(hours[0])))

Output:

Stored: 2026-03-09 13:00:00+00:00
Shown:  Mar 09, 08:00 AM

So 13:00 UTC on March 9 reads as 08:00 AM, since Central Daylight Time had started the day before. Long labels like these often crowd together, and you can rotate the tick labels to fix that.

Step 7: Plot Dates from a CSV File with pandas

Real data usually starts in a file. Here’s a week of check-ins from checkins.csv, where parse_dates turns the text column into true datetimes before plotting. Longer series get fuller treatment in our Matplotlib time series plot guide.

import matplotlib.pyplot as plt
import pandas as pd

df = pd.read_csv("checkins.csv", parse_dates=["date"])
print(df["date"].dtype, "|", len(df), "rows")

fig, ax = plt.subplots(figsize=(7, 3.6), layout="constrained")
ax.plot(df["date"], df["checkins"], "o-")
ax.set_ylabel("Check-ins")
print(type(ax.xaxis.get_major_locator()).__name__)
plt.show()

Output:

datetime64[us] | 7 rows
AutoDateLocator
Matplotlib plot window showing seven days of check-ins loaded from a CSV file as a line with round markers on a date axis
Seven rows from the CSV, plotted on a date axis.

The datetime64 type in the output confirms the conversion happened, and Matplotlib accepts it without extra work.

Step 8: Keep Old Code Running with a Small Helper

Got dozens of calls to migrate? This helper mirrors what the removed method did, so you can update call sites gradually. We ran it on the same check-ins:

import matplotlib.pyplot as plt
from gym_checkins import days, checkins

def plot_date(ax, x, y, fmt="o", tz=None,
              xdate=True, ydate=False, **kwargs):
    """Stand-in for the removed Axes.plot_date."""
    if xdate:
        ax.xaxis_date(tz)
    if ydate:
        ax.yaxis_date(tz)
    return ax.plot(x, y, fmt, **kwargs)

fig, ax = plt.subplots()
lines = plot_date(ax, days, checkins, color="tab:green")
print(len(lines), "line, marker:", lines[0].get_marker())
print(type(ax.xaxis.get_major_locator()).__name__)

Output:

1 line, marker: o
AutoDateLocator

It draws one line with the o marker, which matches the old defaults. I’d treat this as a bridge only; plain ax.plot() is easier for the next person to read.

plot_date to ax.plot Cheat Sheet

Old callReplacement
ax.plot_date(d, y)ax.plot(d, y, "o")
ax.plot_date(d, y, "-")ax.plot(d, y)
ax.plot_date(nums, y)ax.xaxis_date() + ax.plot(nums, y, "o")
ydate=Trueax.plot(x, d, "o") with real dates
tz="America/Chicago"ax.xaxis_date(tz=...) + formatter tz=

Common Mistakes to Avoid When Replacing plot_date

Forgetting the format: plot() draws a line by default, while plot_date() drew markers. If your scatter-like chart suddenly grew a line, add "o".

Plotting text dates: strings become categories, not dates, so date ticks won’t work. This quick check shows the difference:

import matplotlib.pyplot as plt
import pandas as pd

raw = ["2026-03-02", "2026-03-03", "2026-03-04"]
y = [214, 198, 226]

fig, ax = plt.subplots()
ax.plot(raw, y, "o")
print("Text:  ", type(ax.xaxis.get_major_locator()).__name__)

fig, ax = plt.subplots()
ax.plot(pd.to_datetime(raw), y, "o")
print("Dates: ", type(ax.xaxis.get_major_locator()).__name__)

Output:

Text:   StrCategoryLocator
Dates:  AutoDateLocator

StrCategoryLocator means Matplotlib is treating them as labels, and pd.to_datetime() fixes it. If a charting import fails before you even get here, check our fix for no module named matplotlib.

Does plot_date Still Work on Older Matplotlib Versions?

Yes, up to 3.10, though 3.9 and 3.10 flag it as deprecated. Pinning matplotlib<3.11 buys time for a project you can’t change today, but we wouldn’t write new code against it. We tested only 3.11 here, so that history comes from Matplotlib’s own release notes.

Next Steps After Fixing plot_date

Once your chart runs again, you may want a file you can share. Our guide to saving a Matplotlib chart as PNG picks up from here.

A few more date chart walk-throughs from our team:

Frequently asked questions

Is plot_date removed from Matplotlib?

Yes. It was deprecated in 3.9 and removed in 3.11, so calling it raises AttributeError.

What replaces plot_date in Matplotlib?

Use ax.plot(dates, y, "o") with real date or datetime values. Matplotlib builds the date axis automatically.

What did plot_date do differently from plot?

It drew markers with no line by default and marked an axis as holding dates. Otherwise it called plot().

Do I still need date2num with plot?

No. Pass dates directly. If you already have date2num floats, call ax.xaxis_date() so they display as dates.

Why do I get AttributeError for plot_date?

You’re running Matplotlib 3.11 or later, where the function no longer exists. Switch the call to plot().

Where are Matplotlib’s date tools documented?

See the matplotlib.dates reference in the official docs.