@SuHongjun
2020-06-09T01:23:33.000000Z
字数 1387
阅读 297
Python 2020春季学期
import matplotlibimport matplotlib.pyplot as pltimport numpy as npimport xlrd3 #对excel的操作xl = xlrd3.open_workbook(r'E:\Try\Python\综合设计\招商银行(600036)_利润表.xls')#通过索引获取工作表table = xl.sheets()[0]#print(table)# 获取第1行:报表日期riqi = table.row_values(0) #索引从0开始print(riqi)riqi = riqi[1:]print(riqi)riqi = map(int,riqi)riqi = map(str,riqi)print(riqi)riqi = list(riqi)print(riqi)# 获取第3行:营业收入的内容yysr = table.row_values(2) #索引从0开始print(yysr)yysr = yysr[1:]print(yysr)# 获取第26行: 五、净利润的内容jlr = table.row_values(25)print(jlr)jlr = jlr[1:]print(jlr)#.......继续修改........以下代码......labels = riqi#['G1', 'G2', 'G3', 'G4', 'G5']men_means = yysr#[20, 34, 30, 35, 27]women_means = jlr#[25, 32, 34, 20, 25]x = np.arange(len(riqi)) # the label locationswidth = 0.35 # the width of the barsfig, ax = plt.subplots()rects1 = ax.bar(x - width/2, yysr, width, label='yysr')rects2 = ax.bar(x + width/2, jlr, width, label='jlr')# Add some text for labels, title and custom x-axis tick labels, etc.ax.set_ylabel('yysrjlr')ax.set_title('ZSYH yysr jlr') #('招商银行营业收入、净利润')#ax.set_xticks(x)#ax.set_xticklabels(labels)ax.legend()def autolabel(rects):"""Attach a text label above each bar in *rects*, displaying its height."""for rect in rects:height = rect.get_height()ax.annotate('{}'.format(height),xy=(rect.get_x() + rect.get_width() / 2, height),xytext=(0, 3), # 3 points vertical offsettextcoords="offset points",ha='center', va='bottom')#autolabel(rects1)#autolabel(rects2)fig.tight_layout()plt.show()
