Matplotlib Scatter and Multiple Line Charts with Dates

Many guides still draw date charts with plot_date(). It worked for years, but Matplotlib 3.11 removed it, so those scripts now crash on the first call.

In this tutorial, I’ll build matplotlib scatter and multiple line charts with dates using ax.scatter() and ax.plot(), which read Python dates directly.

Every script ran on Matplotlib 3.11.2 and Python 3.12.5, and the outputs are pasted from those runs.

The Sample Store Sales Dates We’ll Plot

I’ll use one dataset throughout: 42 days of made-up sales for three stores, starting March 2, 2026. If the import fails, here’s how to install Matplotlib in Python first. Save this file as store_sales.py:

import random
from datetime import date, timedelta

random.seed(2026)
start = date(2026, 3, 2)
days = [start + timedelta(days=i) for i in range(42)]

def sales(base, growth):
    return [round(base + i * growth + random.gauss(0, 95), 2)
            for i in range(42)]

austin = sales(1850, 14)
denver = sales(1520, 6)
boston = sales(2140, -9)
visitors = [round(s / 7.5 + random.gauss(0, 12)) for s in austin]

if __name__ == "__main__":
    print("Days:", len(days), "from", days[0], "to", days[-1])
    print(f"Austin: first ${austin[0]:,.2f}, last ${austin[-1]:,.2f}")
    print(f"Denver: first ${denver[0]:,.2f}, last ${denver[-1]:,.2f}")
    print(f"Boston: first ${boston[0]:,.2f}, last ${boston[-1]:,.2f}")
    print("Austin visitors, first day:", visitors[0])

Output:

Days: 42 from 2026-03-02 to 2026-04-12
Austin: first $1,932.26, last $2,468.99
Denver: first $1,424.19, last $1,790.48
Boston: first $2,068.41, last $1,533.25
Austin visitors, first day: 249
Command Prompt output of store_sales.py showing 42 days from March 2 to April 12, 2026 with first and last sales for Austin, Denver and Boston
The sample runs from March 2 through April 12, 2026, for all three stores.

Austin starts at $1,932.26 and climbs, while Boston drifts down. The days list holds real date objects, not text, and that’s what the rest of this post depends on.

Why Does plot_date Raise an AttributeError Now?

Here’s the old call on the same Austin numbers:

import matplotlib
import matplotlib.pyplot as plt
from store_sales import days, austin

print("Matplotlib", matplotlib.__version__)
fig, ax = plt.subplots()
ax.plot_date(days, austin)

Output (the error):

Matplotlib 3.11.2
Traceback (most recent call last):
  File "C:\pyguides\old_plot_date.py", line 7, in <module>
    ax.plot_date(days, austin)
    ^^^^^^^^^^^^
AttributeError: 'Axes' object has no attribute 'plot_date'
Command Prompt traceback ending in AttributeError because the Axes object has no attribute plot_date on Matplotlib 3.11
Matplotlib 3.11 no longer has the method, so the script stops here.

I won’t re-teach the migration here. Our guide to the Matplotlib plot_date replacement covers tz, ydate and date2num values. The short version: use the two methods below.

Method 1: Make a Date Scatter Chart with ax.scatter (Recommended)

Use this when each day is a separate reading and a connecting line would suggest a trend that isn’t there. Same Austin data, one call.

Here’s the code:

import matplotlib.pyplot as plt
from store_sales import days, austin

fig, ax = plt.subplots(figsize=(7, 3.6), layout="constrained")
points = ax.scatter(days, austin, s=28, color="tab:blue")
ax.set_title("Austin store: daily sales, spring 2026")
ax.set_ylabel("Sales (USD)")
fig.autofmt_xdate()

print(type(ax.xaxis.get_major_locator()).__name__)
print(len(points.get_offsets()), "points")
plt.show()

Output:

AutoDateLocator
42 points

That draws 42 points, and AutoDateLocator in the output shows Matplotlib built a date axis by itself.

Matplotlib plot window showing 42 days of Austin store sales as blue scatter points on a date axis with slanted labels
Each dot is one day of Austin sales, spread along a real date axis.

How does this code work?

ax.scatter() sees date objects and switches the x axis to date mode without any conversion. s=28 sets the marker area in square points.

fig.autofmt_xdate() slants the labels so they don’t run together. For picking which dates appear, see our walk-through on date ticks and xticks. A longer scatter-only example is in our time series scatter plot post.

Method 2: Split Date Scatter Points into Groups

A scatter gets more useful when color carries meaning. I’ll keep the Austin data and separate weekends from weekdays, using one scatter() call per group so the legend works.

import matplotlib.pyplot as plt
from store_sales import days, austin

pairs = list(zip(days, austin))
weekday = [(d, s) for d, s in pairs if d.weekday() < 5]
weekend = [(d, s) for d, s in pairs if d.weekday() >= 5]

fig, ax = plt.subplots(figsize=(7, 3.6), layout="constrained")
ax.scatter(*zip(*weekday), s=28, color="tab:blue", label="Weekday")
ax.scatter(*zip(*weekend), s=60, color="tab:orange",
           marker="D", label="Weekend")
ax.set_title("Austin store: weekday vs. weekend sales")
ax.set_ylabel("Sales (USD)")
ax.legend(loc="upper left")
fig.autofmt_xdate()

print(len(weekday), "weekdays,", len(weekend), "weekend days")
plt.show()

Output:

30 weekdays, 12 weekend days

The output splits the 42 days into 30 weekdays and 12 weekend days.

Matplotlib plot window showing Austin weekday sales as blue dots and weekend sales as larger orange diamonds on a date axis
Orange diamonds mark the 12 weekend days.

How does this code work?

zip(days, austin) pairs each date with its sale, and weekday() returns 5 or 6 for Saturday and Sunday. *zip(*weekday) unpacks the pairs back into separate x and y lists. More marker ideas are in scatter markers across multiple plots.

Method 3: Plot Multiple Date Lines on One Chart with ax.plot

When you’re comparing trends, lines beat dots. Now all three stores go on one axis. Call ax.plot() once per series, and give each a label.

import matplotlib.pyplot as plt
from store_sales import days, austin, denver, boston

fig, ax = plt.subplots(figsize=(7, 3.6), layout="constrained")
ax.plot(days, austin, label="Austin")
ax.plot(days, denver, label="Denver")
ax.plot(days, boston, label="Boston")
ax.set_title("Daily sales by store, spring 2026")
ax.set_ylabel("Sales (USD)")
ax.set_ylim(bottom=1200)
ax.legend(loc="lower left", ncols=3)
fig.autofmt_xdate()

print(len(ax.lines), "lines,", len(ax.lines[0].get_xdata()), "points each")
plt.show()

Output:

3 lines, 42 points each

That produces 3 lines with 42 points each, all sharing the same date axis.

Matplotlib plot window showing daily sales lines for Austin, Denver and Boston on one date axis with a legend at the bottom left
Austin pulls ahead of Boston by late March on one shared date axis.

How does this code work?

Each ax.plot() adds one line to the same Axes and takes the next color in the cycle. set_ylim(bottom=1200) leaves room so the legend doesn’t cover Denver’s line. Dashes and custom colors are covered in line style and color on date charts.

Method 4: Loop Over a pandas DataFrame for Many Date Lines

Typing one call per store gets old fast. If your data’s in a DataFrame, loop over the columns. These are the same three stores, with a date index.

import matplotlib.dates as mdates
import matplotlib.pyplot as plt
import pandas as pd
from store_sales import days, austin, denver, boston

df = pd.DataFrame({"Austin": austin, "Denver": denver, "Boston": boston},
                  index=pd.to_datetime(days))

fig, ax = plt.subplots(figsize=(7, 3.6), layout="constrained")
for store in df.columns:
    ax.plot(df.index, df[store], marker="o", markersize=3, label=store)

locator = mdates.AutoDateLocator()
ax.xaxis.set_major_locator(locator)
ax.xaxis.set_major_formatter(mdates.ConciseDateFormatter(locator))
ax.set_ylabel("Sales (USD)")
ax.set_ylim(bottom=1200)
ax.legend(loc="lower left", ncols=3)

print(df.index.dtype, "|", len(df.columns), "stores")
print("Best total:", df.sum().idxmax(), float(round(df.sum().max(), 2)))
plt.show()

Output:

datetime64[s] | 3 stores
Best total: Austin 89266.47

Austin has the highest total, at $89,266.47 across the 42 days.

Matplotlib plot window showing three store sales lines with small markers from a pandas DataFrame and compact month and day labels