Matplotlib Tutorial Part 05 - Stack Plots


In [1]:
%matplotlib inline
import matplotlib.pyplot as plt

In [2]:
fig = plt.figure(figsize=(17,9))
# X Axis
days = [1,2,3,4,5]

# Data
sleeping = [7,8,6,11,7]
eating = [2,3,4,3,2]
working = [7,8,7,2,2]
playing = [8,5,7,8,13]

# Labels
plt.plot([],[],color='m', label='Sleeping',linewidth=5)
plt.plot([],[],color='c', label='Eating',linewidth=5)
plt.plot([],[],color='r', label='Working',linewidth=5)
plt.plot([],[],color='k', label='Playing',linewidth=5)

# Stack Plot
plt.stackplot(days, sleeping, eating, working, playing, colors=['m','c','r','k'])

# Plotting
plt.xlabel('x')
plt.ylabel('y')
plt.title('Stack Plots')
plt.legend()

plt.show()