#250 Basic Stacked Area Chart

 

 

 

 

 

 

This page describes how to realise a stacked area chart using the Matplotlib library of python. This is done using the stackplot() function. There are 2 ways to use this function, as described below:

 

 

 

 

 


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

# --- FORMAT 1

# Your x and y axis
x=range(1,6)
y=[ [1,4,6,8,9], [2,2,7,10,12], [2,8,5,10,6] ]

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

# --- FORMAT 2</pre>
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')

Leave a Reply

Your email address will not be published.