堆叠图


Matplotlib堆叠图

import matplotlib.pyplot as plt
import matplotlib

# 设置中文字体
matplotlib.rcParams['axes.unicode_minus'] = False
matplotlib.rcParams['font.sans-serif'] = ['Microsoft YaHei']
matplotlib.rcParams['font.family']='sans-serif'


days = [1,2,3,4,5]

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

plt.plot([],[],color='m', label='睡觉', linewidth=5)
plt.plot([],[],color='c', label='吃饭', linewidth=5)
plt.plot([],[],color='r', label='工作', linewidth=5)
plt.plot([],[],color='k', label='玩耍', linewidth=5)

plt.stackplot(days, sleeping, eating, working, playing, colors=['m','c','r','k'])
plt.xlabel('x')
plt.ylabel('y')
plt.title('编程字典-matplotlib教程')
plt.legend()
plt.show()