import matplotlib.pyplot as plt days = [1,2,3,4,5] sleeping = [7,8,6,11,7] eating = [3,3,4,2,3] working = [7,8,7,3,2] playing = [7,5,7,8,12] #stack chart 没有图例,所以用这种方式加上图例 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) plt.stackplot(days, sleeping, eating, working, playing, colors=[‘m‘,‘c‘,‘r‘,‘k‘]) plt.xlabel(‘x‘) plt.ylabel(‘y‘) plt.title(‘stack chart\n‘) plt.legend() plt.show()
如下图
时间: 2024-10-07 02:02:59