A logistics manager in Nevada wants matplotlib line style and color changes on a daily shipments chart: the forecast dashed and each warehouse in its own color. You find an old snippet that passes linestyle to plot_date(), and it crashes.
Matplotlib 3.11 removed that function, but ax.plot() takes real dates and the same options.
In this tutorial, I’ll set matplotlib line style and color on a date-axis chart, plus widths, markers and per-series styles.
Quick answer: pass real dates to ax.plot() and style the line with keyword arguments:
ax.plot(days, values, linestyle="--", color="crimson", linewidth=2)
fig.autofmt_xdate()
All the output in this post came from running the scripts on Matplotlib 3.11.2 and Python 3.12.5.
The Warehouse Shipments Data Behind These Line Styles
One made-up dataset runs throughout: 45 days of shipments for Reno, Memphis and Columbus, starting Monday, January 12, 2026. New to this? Start with how to plot a line in Matplotlib. Save this as warehouse.py:
import random
from datetime import date, timedelta
random.seed(2026)
start = date(2026, 1, 12)
days = [start + timedelta(days=i) for i in range(45)]
def shipments(base, growth):
return [round(base + i * growth + random.gauss(0, 11))
for i in range(45)]
reno = shipments(340, 1.6)
memphis = shipments(255, 0.7)
columbus = shipments(175, -0.5)
average = [round((a + b + c) / 3, 1)
for a, b, c in zip(reno, memphis, columbus)]
if __name__ == "__main__":
print("Days:", len(days), "from", days[0], "to", days[-1])
print("Reno first/last:", reno[0], reno[-1])
Output:
Days: 45 from 2026-01-12 to 2026-02-25
Reno first/last: 350 420

Reno goes from 350 to 420 shipments over the period. days holds Python date objects, so Matplotlib builds a date axis without any conversion.
Why plot_date No Longer Takes a linestyle
Here’s the old call, using the same Reno numbers:
import matplotlib.pyplot as plt
from warehouse import days, reno
fig, ax = plt.subplots()
ax.plot_date(days, reno, linestyle="--", color="red")
Output (the error):
Traceback (most recent call last):
File "C:\pyguides\pydemo\old_plot_date.py", line 5, in <module>
ax.plot_date(days, reno, linestyle="--", color="red")
^^^^^^^^^^^^
AttributeError: 'Axes' object has no attribute 'plot_date'

AttributeError.Swap plot_date for plot and keep your style arguments. The rest of the migration is in our plot_date replacement guide.
How Do You Change the Line Style and Color on a Date Line?
Add linestyle and color to the plot call. This is the Reno line, dashed and red:
import matplotlib.pyplot as plt
from warehouse import days, reno
fig, ax = plt.subplots(figsize=(7, 3.6), layout="constrained")
line, = ax.plot(days, reno, linestyle="--", color="crimson")
ax.set_ylabel("Shipments")
fig.autofmt_xdate()
print(line.get_linestyle(), line.get_color(), line.get_linewidth())
plt.show()
Output:
-- crimson 1.5
The output confirms the -- style, crimson and the default 1.5-point width.

fig.autofmt_xdate() slants the labels so they can’t collide. To choose which dates get labels, see this walk-through on date ticks and xticks.
The Four Named Matplotlib Linestyle Values
Matplotlib has four named styles, and each has a short form. Here’s one on each series:
import matplotlib.pyplot as plt
from warehouse import days, reno, memphis, columbus, average
series = [("solid", reno), ("dashed", memphis),
("dashdot", columbus), ("dotted", average)]
fig, ax = plt.subplots(figsize=(7, 3.8), layout="constrained")
for style, values in series:
ax.plot(days, values, linestyle=style, label=style)
ax.set_ylabel("Shipments")
fig.legend(loc="outside upper center", ncols=4)
fig.autofmt_xdate()
print([line.get_linestyle() for line in ax.lines])
plt.show()
Output:
['-', '--', '-.', ':']
The output lists the short codes Matplotlib stores.

| Name | Short form | Good for |
|---|---|---|
solid | - | The main series |
dashed | -- | Forecasts, targets |
dashdot | -. | A third series |
dotted | : | Averages, references |
Need another rhythm? Pass an (offset, (on, off)) tuple as the style, as this guide to dashed line spacing shows.
Set a Line Color by Name, Hex, RGB or Gray
color accepts several formats. This chart uses one of each:
import matplotlib.colors as mcolors
import matplotlib.pyplot as plt
from warehouse import days, reno, memphis, columbus, average
series = [("crimson", reno), ("#2E8B57", memphis),
((0.2, 0.4, 0.8), columbus), ("0.45", average)]
fig, ax = plt.subplots(figsize=(7, 3.8), layout="constrained")
for color, values in series:
ax.plot(days, values, color=color, linewidth=2, label=str(color))
ax.set_ylabel("Shipments")
fig.legend(loc="outside upper center", ncols=4)
fig.autofmt_xdate()
print([mcolors.to_hex(color) for color, _ in series])
plt.show()
Output:
['#dc143c', '#2e8b57', '#3366cc', '#737373']
to_hex() converts each one to the same form: #dc143c, #2e8b57, #3366cc and #737373.

RGB tuples use 0 to 1 values, and "0.45" is a shade of gray. For a longer list of options, see plotting multiple lines in different colors.
Add Line Width and Markers to a Date Line
On 45 days, a marker on every point is clutter, so markevery=7 marks one point per week on the Reno line:
import matplotlib.pyplot as plt
from warehouse import days, reno
fig, ax = plt.subplots(figsize=(7, 3.6), layout="constrained")
line, = ax.plot(days, reno, color="tab:blue", linewidth=2.5,
marker="o", markersize=8,
markerfacecolor="white", markeredgecolor="tab:blue",
markevery=7)
ax.set_ylabel("Shipments")
fig.autofmt_xdate()
marked = days[::7]
print(len(marked), "markers, first on", f"{marked[0]:%A, %B %d, %Y}")
plt.show()
Output:
7 markers, first on Monday, January 12, 2026
That puts 7 markers on the line, starting on Monday, January 12, 2026.

markerfacecolor fills the circle and markeredgecolor draws its outline. There’s more on this pairing in our guide to a dashed line with markers.
Use a Matplotlib Format String for Color and Linestyle
A format string packs color, marker and line style into one argument, such as g-- or mo:. It’s the shortest option:
import matplotlib.pyplot as plt
from warehouse import days, reno, memphis
fig, ax = plt.subplots(figsize=(7, 3.6), layout="constrained")
ax.plot(days, reno, "g--", label="g--")
ax.plot(days, memphis, &