![6536d3b7136e6d2a84ef2139c6f6c474.png](https://i-blog.csdnimg.cn/blog_migrate/f74571fc38005747b19c301210a34f29.jpeg)
图示:
![5de8ee4fbdb17e8ee04ff6af5682d05a.png](https://i-blog.csdnimg.cn/blog_migrate/ce735e0d0ff034ed242d604303cffd8e.jpeg)
代码:
import matplotlib as mplimport matplotlib.pyplot as pltimport numpy as npmpl.rcParams['font.sans-serif'] = ['SimHei']mpl.rcParams['axes.unicode_minus'] = Falsex = range(1,6)y1 = [1,2,3,4,5]y2 = [1,2,3,4,5]y3 = [1,2,3,4,5]labels = ["蓝色区域","棕色区域","绿色区域"]colors = ["#8da0cb","#fc8d62","#66c2a5"]# 绘图plt.stackplot(x,y1,y2,y3,labels=labels,colors=colors)# 图例plt.legend(loc="upper left")# 显示图形plt.show()