python堆积折线图
import matplotlib import matplotlib.pyplot as plt x = [1,2,3,4,5,6,7,8,9] y = [1,1,2,15,47,78,54,69,45] y1 = [0,0,2,2,1,10,37,40,35] y2 = [0,0,4,6,6,32,73,66,58] y3 = [0,0,0,4,4,5,12,12,14] y4 = [0,0,0,1,1,4,24,71,41] y5 = [0,0,0,1,0,3,0,0,0] y6 = [0,0,0,1,0,2,0,1,0] y7 = [0,0,0,0,0,1,3,13,3] y8 = [0,0,0,0,0,0,5,6,11] y9 = [0,0,0,0,0,0,1,2,0] fig, ax = plt.subplots(facecolor=‘white’,figsize=(16,11)) labels = [“1影视”, “2动画”, “3生活”, “4游戏”,“5社科”,“7舞蹈”,“8动物圈”,“9歌曲”,“10运动”,“11鬼畜”] colors = [“#8da0cb”, “#fc8d62”, “#dbdcdc”, “#7ea1b8”,“#a7d4d7”,“#f2f2f2”,“lightblue”,“lemonchiffon”,“lavender”,“#a1b1b9”] plt.xticks((1,2,3,4,5,6,7,8,9), (‘2014’,‘2015’,‘2016’,‘2017’, ‘2018’,‘2019’,‘2020’,‘2021’,‘2022’), fontsize=10)#, rotation=90 plt.stackplot(x,y,y1,y2, y3,y4,y5,y7,y8,y9, labels=labels, colors=colors, alpha=0.5) plt.ylim((0, 300)) plt.legend(loc=“upper left”) plt.xlabel(“Year”, fontsize=13) plt.ylabel(“Number”, fontsize=13) plt.show() fig.savefig(‘堆积折线图.jpg’, dpi=100)
|