Make a Plotly area chart with px.area(df, x=..., y=..., color=...). Plotly Express stacks the areas by default, so each band sits on top of the one below it and the top edge is the total. Add groupnorm="percent" for a 100% stacked area chart, or switch a single trace to fill="tozeroy" for a plain filled line. The code was written for Plotly 7.2 and also runs on Plotly 6.
Quick Example
import numpy as np
import pandas as pd
import plotly.express as px
# Monthly website sessions by traffic source, January 2024 to June 2026
rng = np.random.default_rng(23)
months = pd.date_range("2024-01-01", periods=30, freq="MS")
t = np.arange(len(months))
trend = {
"Search": 50_000 + 300 * t,
"Social": 9_000 + 1_100 * t,
"Email": 14_000 - 150 * t,
"Referral": 8_000 + 80 * t,
}
visits = pd.DataFrame({
"month": np.tile(months, len(trend)),
"source": np.repeat(list(trend), len(months)),
"sessions": np.concatenate(
[v * rng.normal(1, 0.04, len(months)) for v in trend.values()]
).round().astype(int),
})
fig = px.area(
visits, x="month", y="sessions", color="source",
color_discrete_sequence=["#264653", "#e76f51", "#e9c46a", "#2a9d8f"],
labels={"month": "", "sessions": "Sessions per month", "source": ""},
title="Monthly sessions by traffic source",
)
fig.show()
visits is in long form: one row per month and source. Plotly Express draws one area per value of color and stacks them in the order they first appear in the data, so Search is the bottom band. Total sessions grow from 81,961 in January 2024 to 126,840 in June 2026, and the chart shows where the growth comes from: Social goes from 8,643 to 41,836 sessions while Email shrinks from 13,953 to 9,378.
Use wide-form data
If the data has one column per series, pass the columns to y as a list, or pass the whole DataFrame with the index on the x-axis:
wide = visits.pivot(index="month", columns="source", values="sessions")
fig = px.area(wide) # every column, index as x
fig = px.area(wide, y=["Search", "Social"]) # only some columns
print(len(fig.data), "areas")
Long form is easier when you want to color, facet, or filter by another column. Wide form is quicker when you already have a pivoted table. Both give the same chart.
How do I make a 100% stacked area chart?
Add groupnorm="percent". Plotly rescales every x position so the bands add up to 100, which shows the mix instead of the total. The y-axis title stays as it was, so replace it:
fig = px.area(
visits, x="month", y="sessions", color="source", groupnorm="percent",
color_discrete_sequence=["#264653", "#e76f51", "#e9c46a", "#2a9d8f"],
labels={"month": "", "sessions": "Share of sessions (%)", "source": ""},
title="Share of monthly sessions by traffic source",
)
fig.update_yaxes(ticksuffix="%")
fig.show()

The percent version makes the shift in mix easy to see: Search falls from 62.4% of sessions to 51.5%, Social climbs from 10.5% to 33.0%, and Email drops from 17.0% to 7.4%, even though Search's session count grew. groupnorm="fraction" gives 0 to 1 instead of 0 to 100. Use the percent chart for the mix and the absolute chart for the total. Percent charts hide whether the whole pie grew.
Change the stack order
The first series sits at the bottom. To reorder, list the categories in category_orders:
fig = px.area(
visits, x="month", y="sessions", color="source",
category_orders={"source": ["Social", "Email", "Referral", "Search"]},
color_discrete_map={"Search": "#264653", "Social": "#e76f51",
"Email": "#e9c46a", "Referral": "#2a9d8f"},
labels={"month": "", "sessions": "Sessions per month", "source": ""},
title="Fastest-changing source at the bottom",
)
fig.show()

Put the series you want readers to compare at the bottom, because every band above it floats on a moving baseline and is hard to read precisely. Only the bottom band starts at zero. color_discrete_map pins each category to a color, so the colors stay with their sources when the order changes.
Overlapping filled lines instead of a stack
A stack answers "how much in total", but sometimes the series should be compared with each other. Turn off the stacking by setting stackgroup=None and fill each trace down to zero, then lower the opacity so the one behind shows through:
pair = visits[visits["source"].isin(["Email", "Social"])]
fig = px.area(
pair, x="month", y="sessions", color="source",
color_discrete_map={"Email": "#e9c46a", "Social": "#e76f51"},
labels={"month": "", "sessions": "Sessions per month", "source": ""},
title="Social overtakes Email",
)
fig.update_traces(stackgroup=None, fill="tozeroy", opacity=0.6)
fig.show()

Social first passes Email in April 2024 and stays ahead in every month after. Overlap works for two or three series. With more, the colors blend and a plain px.line is clearer.
Build a stacked area chart with graph_objects
In plotly.graph_objects, a trace joins a stack when it has a stackgroup. Every trace with the same stackgroup string is stacked together, and groupnorm goes on the trace too:
import plotly.graph_objects as go
colors = {"Search": "#264653", "Social": "#e76f51", "Email": "#e9c46a", "Referral": "#2a9d8f"}
fig = go.Figure()
for source in wide.columns[::-1]:
fig.add_trace(go.Scatter(
x=wide.index, y=wide[source], name=source, mode="lines",
line=dict(width=0.5, color=colors[source]), stackgroup="one",
))
fig.update_layout(title="Monthly sessions by traffic source", hovermode="x unified")
fig.show()
This draws the same stacked chart as the Quick Example, with one extra: hovermode="x unified" shows every source for the month in one tooltip. wide.columns[::-1] is there because wide has its columns in alphabetical order and the loop builds the stack bottom to top. Without stackgroup, a go.Scatter with fill="tozeroy" draws an independent filled line.
Shade the band between two lines
fill="tonexty" fills from a trace to the trace added just before it. That makes a range band: draw the lower line, then the upper line with fill="tonexty", then the line you actually care about:
total = wide.sum(axis=1)
band = total.rolling(6).agg(["min", "max"]).dropna()
fig = go.Figure()
fig.add_trace(go.Scatter(x=band.index, y=band["min"], mode="lines",
line=dict(width=0), hoverinfo="skip", showlegend=False))
fig.add_trace(go.Scatter(x=band.index, y=band["max"], mode="lines", line=dict(width=0),
fill="tonexty", fillcolor="rgba(38, 70, 83, 0.18)",
name="6-month range"))
fig.add_trace(go.Scatter(x=total.index, y=total, mode="lines",
line=dict(color="#264653", width=2.5), name="Total sessions"))
fig.update_layout(title="Total monthly sessions with the 6-month range",
yaxis_title="Sessions per month", template="plotly_white")
fig.show()

Each point in the band is the lowest and highest monthly total of the latest six months, so a line along the top edge is setting new highs, as it does in four of the first six months of 2026. The same pattern works for confidence intervals: see line charts with a confidence interval. The first trace has width=0 so only the fill shows, and hoverinfo="skip" keeps the invisible line out of the tooltip.
Which area chart should I use?
| You want | Use |
|---|---|
| A total split into parts over time | px.area(df, x=, y=, color=) |
| The mix, not the total | groupnorm="percent" |
| To compare series that overlap | update_traces(stackgroup=None, fill="tozeroy", opacity=0.6) |
| One series, filled to zero | px.area(df, x=, y=) |
| A range or interval around a line | go.Scatter with fill="tonexty" |
| Custom hover, or traces added in a loop | go.Scatter(stackgroup="one") |
Practical Tips
- Don't stack series that can't be added. The top edge reads as a total, so stack only parts of a whole (visits by source, cost by department). Stacking two prices or two rates gives a meaningless top line.
- Avoid negative values. Stacked areas with values below zero overlap and fold back on themselves. Use a grouped or stacked bar chart for values that cross zero.
- Keep it to about five bands. Past that, the middle bands are hard to tell apart. Group the small ones into "Other".
- Use
px.linewhen the total doesn't matter. An area chart suggests a quantity measured from zero. For a single series the filled area adds nothing over a line unless you want the emphasis. - Matplotlib version: area charts and stacked area charts in Matplotlib uses
stackplotandfill_betweenfor the same charts.
