@SuHongjun
2020-06-09T01:23:33.000000Z
字数 1387
阅读 267
Python
2020春季学期
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import 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 locations
width = 0.35 # the width of the bars
fig, 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 offset
textcoords="offset points",
ha='center', va='bottom')
#autolabel(rects1)
#autolabel(rects2)
fig.tight_layout()
plt.show()