Stacked area Chart

logo of a chart:StackedArea

A stacked area chart displays the evolution of a numeric variable for several groups of a dataset. Each group is displayed on top of each other, making it easy to read the evolution of the total, but hard to read each group value accurately. In python, stacked area charts are mainly done thanks to the stackplot() function

⏱ Quick start

# library
import numpy as np
import matplotlib.pyplot as plt

# Create data
x=range(1,6)
y1=[1,4,6,8,9]
y2=[2,2,7,10,12]
y3=[2,8,5,10,6]

# Basic stacked area chart.
plt.stackplot(x,y1, y2, y3, labels=['A','B','C'])
plt.legend(loc='upper left')

Matplotlib logoStacked Area chart with Matplotlib

Matplotlib is the most common way to build a stacked area chart with Python. The examples below start by explaining to basics of the stackplot() function. The also describe the most common type of customization like changing colors, controling group order and more.

🔎 stackplot() function parameters→ see full doc

→ Description

The stackplot() function from matplotlib creates a stacked area plot. This type of plot is used to show how multiple variables change over time, with each variable stacked on top of the previous ones. It's particularly useful for visualizing the composition of a whole over time.

→ Arguments

Matplotlib logoBest python stacked area chart examples

The web is full of astonishing charts made by awesome bloggers, (often using R). The Python graph gallery tries to display (or translate from R) some of the best creations and explain how their source code works. If you want to display your work here, please drop me a word or even better, submit a Pull Request!

Contact


👋 This document is a work by Yan Holtz. You can contribute on github, send me a feedback on twitter or subscribe to the newsletter to know when new examples are published! 🔥