Skip to content
svgbrushablearea

Area chart

How large is a quantity over time (and how do overlapping series compare)?

Demo data · seed 20261101 · 728 rows · default settings · 640 × 360SVG, lightSVG, darkDemo CSV

How to read it

  1. Read the top edge of each area as its value.
  2. Where areas overlap, follow the edges: the series aren't stacked.
  3. Check the baseline: a filled area implies a meaningful zero.
  1. Callout 1: This series' top edge is its value.
  2. Callout 2: Overlap: both series are measured from zero.
  3. Callout 3: Series cross here.

Watch out

  • If zero means nothing for this measure (temperature, an index), use a line instead.

Defaults

Resample
ISO week
Combine values into days, weeks or months before plotting, to reduce noise.
Also: None (raw) · Day · Month · Quarter
Zero baseline
On
Start the y axis at zero.
Fill opacity
0.2
How see-through the filled areas are.
Range 0.1 to 0.8, step 0.05

Pinned in the code

  • Same resampling as the line chart (UTC period start; ISO weeks; period mean).
  • Areas are filled down to zero by default, so the area is proportional to the value; turn the baseline off only for values far from zero.
  • Series overlap (they are not stacked); see the stacked-area recipe for parts of a whole.
  • All calendar arithmetic is in UTC; timestamps are epoch milliseconds.

Use with care

Filled areas imply magnitude from zero — keep the zero baseline unless the values are far from zero.

# Area chart — Codesplash Chart Lab (recipe "area")
# controls: period=week, zero=true, opacity=0.2
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy import stats

try:
    import codesplash as cs  # optional: the app's chart theme
except ImportError:
    cs = None
if cs:
    cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]

df = pd.read_csv("area-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["day"] = pd.to_datetime(df["day"])
df["platform"] = pd.Categorical(df["platform"].astype("string"), categories=["Web", "App"])

def freq_levels(s, k=8):
    """Declared level order when the column is categorical, else by descending count (ties A→Z)."""
    if isinstance(s.dtype, pd.CategoricalDtype):
        return [str(v) for v in s.cat.categories][:k]
    vc = s.dropna().astype(str).value_counts()
    return sorted(vc.index, key=lambda v: (-vc[v], v))[:k]
def period_start(t, period):
    """UTC period start: day, ISO week (Monday), month, quarter or year; "none" keeps the timestamp."""
    if period == "none":
        return t
    day = t.dt.floor("D")
    if period == "day":
        return day
    if period == "week":
        return day - pd.to_timedelta(day.dt.day_of_week, unit="D")
    return t.dt.to_period({"month": "M", "quarter": "Q", "year": "Y"}[period]).dt.start_time

def resample(d, time, value, period, level=0.95):
    """Per period: n, mean, SD (n − 1), min, max and mean ± t(0.975, n − 1)·SD/√n (no band when n = 1)."""
    d = d.dropna(subset=[time, value])
    s = d.groupby(period_start(d[time], period))[value].agg(["count", "mean", "std", "min", "max"])
    s = s.rename(columns={"count": "n"}).rename_axis("t").reset_index()
    half = (stats.t.ppf(1 - (1 - level) / 2, s["n"] - 1) * s["std"] / np.sqrt(s["n"])).fillna(0)
    return s.assign(lo=s["mean"] - half, hi=s["mean"] + half)

PERIOD = "week"
series = [(lv, df[df["platform"].astype(str) == lv]) for lv in freq_levels(df["platform"], 8)]
fig, ax = plt.subplots(figsize=(8, 4))
for i, (name, d) in enumerate(series):  # overlapping areas, not stacked
    s = resample(d, "day", "active_users", PERIOD)
    col = PALETTE[i % len(PALETTE)]
    ax.fill_between(s["t"], 0, s["mean"], color=col, alpha=0.2, linewidth=0)  # filled down to zero: area ∝ value
    ax.plot(s["t"], s["mean"], color=col, linewidth=1.6, label=name)
ax.set_ylabel("active_users")
ax.set_xlabel("day (UTC)")
ax.legend(title="platform", fontsize=8)
plt.show()

Needs pandas, numpy, matplotlib, scipy · reads area-demo.csv · app theme from the optional codesplash helper