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

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'

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

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

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

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

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 call | Replacement |
|---|---|
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=True | ax.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:
- Scatter and multi-line charts with dates
- Bar charts with dates in Matplotlib
- Add a vertical line at a date
- Multiple plots in one Matplotlib figure
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.

Bijay Kumar is a 13-time Microsoft MVP with more than 18 years in software development, and the founder of Python Guides and TSinfo Technologies. He started out building .NET and SharePoint solutions at HP, TCS and KPIT before moving into Python, machine learning and AI, and he also builds web apps with TypeScript and React. He writes the tutorials here himself, and every example is run before publishing so you see the real output. More about Bijay · Microsoft MVP profile · LinkedIn