生成叠加柱状图和水平柱状图

 1 import pandas
 2 from matplotlib  import  pyplot
 3 excel=pandas.read_excel('填充日期.xlsx')
 4 
 5 pyplot.rcParams['font.sans-serif']=['simhei'] #显示中文标签
 6 pyplot.rcParams['axes.unicode_minus']=False
 7 
 8 
 9 
10 #按是从score1,score2,score3三者之和排序
11 excel['total']=excel['score1']+excel['score2']+excel['score3']
12 excel.sort_values(by='total',inplace=True)
13 
14 excel.plot.bar(x='name',y=['score1','score2','score3'],stacked=True,title='分数')  #生成叠加柱状图
15 pyplot.xlabel('姓名')
16 pyplot.ylabel('分数')
17 
18 
19 #生成水平柱状图
20 excel.plot.barh(x='name',y=['score1','score2','score3'],stacked=True,title='分数')
21 
22 pyplot.xlabel('分数')
23 pyplot.ylabel('姓名')
24 
25 
26 
27 
28 pyplot.tight_layout()
29 pyplot.show()
原文地址:https://www.cnblogs.com/luckiness/p/13083015.html