Pandas Stacked Area Chart

logo of a chart:StackedArea

This post explains how to create a stacked area plot using the pandas library of python.

Using pandas library, the stacked area charts are plotted with the plot.area() function. Each column of your data frame will be plotted as an area on the chart.

# libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
 
# Dataset
df = pd.DataFrame(np.random.rand(10, 4), columns=['a', 'b', 'c', 'd'])
 
# plot
df.plot.area()

# show the graph
plt.show()

Timeseries

Contact & Edit


👋 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! 🔥

This page is just a jupyter notebook, you can edit it here. Please help me making this website better 🙏!