Stacked area chart
A stacked area chart layers several series on top of each other, so the top edge is the total and each band is one component's contribution over time.
When to use it
- Components add up to a meaningful total over time.
- The total trend matters as much as the mix.
Watch out: Only the bottom layer has a flat baseline. Put the most important or most stable series at the bottom.
Ask for it in pltchat
Upload your file and type something like:
"stacked area chart of traffic by source over time"
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
rng = np.random.default_rng(16)
weeks = pd.date_range("2024-01-01", periods=52, freq="W")
t = np.arange(52)
sources = {"Search": 400 + 6 * t, "Direct": 300 + 2 * t,
"Social": 100 + 40 * np.sin(t / 5) + 4 * t, "Email": 80 + 0 * t}
sources = {k: v + rng.normal(0, 15, 52) for k, v in sources.items()}
fig, ax = plt.subplots(figsize=(6.4, 4))
ax.stackplot(weeks, sources.values(), labels=sources.keys(), alpha=0.85)
ax.set_ylabel("Weekly visits")
ax.legend(loc="upper left")
fig.autofmt_xdate()
plt.tight_layout()
plt.show()
Upload a CSV, Excel, JSON or Parquet file. Your first plot is always free.