一、Python繪制面積圖對應代碼如下圖所示
import matplotlib.pyplot as plt from pylab import mpl mpl.rcParams['font.sans-serif'] = ['STZhongsong'] # 指定默認字體:解決plot不能顯示中文問題 mpl.rcParams['axes.unicode_minus'] = False plt.figure(figsize=(9,6)) X=['2021年1月','2021年2月','2021年3月','2021年4月','2021年5月','2021年6月'] A商品=[12,9,6,13,10,12] B商品=[8,6,10,7,9,11] C商品=[11,12,9,12,10,9] plt.stackplot(X,A商品,B商品,C商品) plt.xlabel('日期') plt.ylabel('數量') plt.title('面積圖',fontsize = 18) plt.legend(['A商品','B商品','C商品'],fontsize = 10,loc='best')#顯示圖例 plt.show()
二、對應效果圖如下所示


