years = sorted(top8["Year"].unique())
wide = top8.pivot(index="Year", columns="Entity", values="share_pct").reindex(years)
wide = wide.fillna(0)
fills = [
"rgba(180,83,9,0.35)", "rgba(15,118,110,0.32)", "rgba(29,78,216,0.28)",
"rgba(124,58,237,0.26)", "rgba(190,18,60,0.24)", "rgba(100,116,139,0.22)",
"rgba(202,138,4,0.2)", "rgba(3,105,161,0.2)",
]
fig2 = go.Figure()
for i, entity in enumerate(top_entities):
if entity not in wide.columns:
continue
fig2.add_trace(go.Scatter(
x=wide.index,
y=wide[entity],
name=entity,
stackgroup="one",
mode="lines",
line=dict(width=0.5),
fillcolor=fills[i % len(fills)],
hovertemplate=f"{entity}: %{{y:.1f}}%<extra></extra>",
))
fig2.update_layout(
**THEME,
xaxis=dict(title=""),
yaxis=dict(title="Percent of summed country totals", range=[0, 100]),
)
apply_mm_layout(
fig2,
"Share of estimated world oil output: eight largest producers (100% stacked)",
subtitle=(
"World total = sum of country-level series in dataset "
"(excludes regional aggregates)"
),
legend_position="top",
n_legend_items=len(top_entities),
)
add_source(fig2)
assert_no_title_overlap(fig2)
fig2.show()