[关闭]
@SuHongjun 2020-06-09T01:23:33.000000Z 字数 1387 阅读 267

Python Day24:综合作业(3)

Python 2020春季学期


未完成及不完善部分就留给同学们去继续努力啦!

  1. import matplotlib
  2. import matplotlib.pyplot as plt
  3. import numpy as np
  4. import xlrd3 #对excel的操作
  5. xl = xlrd3.open_workbook(r'E:\Try\Python\综合设计\招商银行(600036)_利润表.xls')
  6. #通过索引获取工作表
  7. table = xl.sheets()[0]
  8. #print(table)
  9. # 获取第1行:报表日期
  10. riqi = table.row_values(0) #索引从0开始
  11. print(riqi)
  12. riqi = riqi[1:]
  13. print(riqi)
  14. riqi = map(int,riqi)
  15. riqi = map(str,riqi)
  16. print(riqi)
  17. riqi = list(riqi)
  18. print(riqi)
  19. # 获取第3行:营业收入的内容
  20. yysr = table.row_values(2) #索引从0开始
  21. print(yysr)
  22. yysr = yysr[1:]
  23. print(yysr)
  24. # 获取第26行: 五、净利润的内容
  25. jlr = table.row_values(25)
  26. print(jlr)
  27. jlr = jlr[1:]
  28. print(jlr)
  29. #.......继续修改........以下代码......
  30. labels = riqi#['G1', 'G2', 'G3', 'G4', 'G5']
  31. men_means = yysr#[20, 34, 30, 35, 27]
  32. women_means = jlr#[25, 32, 34, 20, 25]
  33. x = np.arange(len(riqi)) # the label locations
  34. width = 0.35 # the width of the bars
  35. fig, ax = plt.subplots()
  36. rects1 = ax.bar(x - width/2, yysr, width, label='yysr')
  37. rects2 = ax.bar(x + width/2, jlr, width, label='jlr')
  38. # Add some text for labels, title and custom x-axis tick labels, etc.
  39. ax.set_ylabel('yysrjlr')
  40. ax.set_title('ZSYH yysr jlr') #('招商银行营业收入、净利润')
  41. #ax.set_xticks(x)
  42. #ax.set_xticklabels(labels)
  43. ax.legend()
  44. def autolabel(rects):
  45. """Attach a text label above each bar in *rects*, displaying its height."""
  46. for rect in rects:
  47. height = rect.get_height()
  48. ax.annotate('{}'.format(height),
  49. xy=(rect.get_x() + rect.get_width() / 2, height),
  50. xytext=(0, 3), # 3 points vertical offset
  51. textcoords="offset points",
  52. ha='center', va='bottom')
  53. #autolabel(rects1)
  54. #autolabel(rects2)
  55. fig.tight_layout()
  56. plt.show()
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注