Plot guides › Chart types

Line chart with multiple series

Several lines on shared axes show how groups move relative to each other. With a long-format table (one row per group and x value), a groupby loop draws one line per group.

Example line chart with multiple series made with matplotlib
Rendered from the code below, with example data.

When to use it

Watch out: Past five or six lines the chart turns into spaghetti. Use small multiples instead.

Ask for it in pltchat

Upload your file and type something like:

"one line per region, x = year, y = sales, legend outside on the right"

pltchat writes the loader and the plot for your columns, runs it in your browser and shows you the code.

The matplotlib code

Self-contained with example data; swap in pd.read_csv(...) or pd.read_excel(...) for your own file.

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

# Example data in long format: one row per (region, year)
rng = np.random.default_rng(1)
years = np.arange(2015, 2025)
df = pd.DataFrame([
    {"region": r, "year": y, "sales": base + 3 * i + rng.normal(0, 2)}
    for r, base in [("North", 20), ("South", 28), ("East", 15), ("West", 24)]
    for i, y in enumerate(years)
])

fig, ax = plt.subplots(figsize=(6.4, 4))
for region, group in df.groupby("region"):
    ax.plot(group["year"], group["sales"], marker="o", label=region)
ax.set_xlabel("Year")
ax.set_ylabel("Sales (units)")
ax.legend(title="Region", loc="center left", bbox_to_anchor=(1, 0.5))
ax.grid(alpha=0.3)
plt.tight_layout()
plt.show()

Make this with your data

Upload a CSV, Excel, JSON or Parquet file. Your first plot is always free.

Related plots