Python代码为:
import pandas as pd import matplotlib.pyplot as plt from pylab import mpl mpl.style.use('classic') mpl.rcParams['font.sans-serif'] = ['SimHei'] filename = u'成绩数据表.xlsx' sheetname = u'15班' item = u'数学成绩' bins = [0,50,60,70,80,90,101] # bins = [0,50,60,70,80,90,95,100] df = pd.read_excel(filename, sheet_name=sheetname) datalist = df[item] cats = pd.cut(datalist, bins, right=False) vc = pd.value_counts(cats).sort_index() average = round(datalist.sum()/vc.sum(), 2) plt.title(u"(Average score:"+str(average)+ u", Examinees:"+str(vc.sum()) +u")", fontsize=20) xt = range(len(bins)+1,2*len(bins)) rects = plt.bar(xt, vc, width=1, align="center",color="b") for i in range(len(bins)-1): h = vc.values[i] x = xt[i] if h != 0: plt.text(x, h, str(int(h)), ha="center", va="bottom", fontsize=20) plt.xticks(xt, vc.index, fontsize= 100//len(bins)) plt.yticks(fontsize=20) plt.tight_layout() plt.savefig(sheetname+item + u".png") plt.show()
表格主要信息
成绩数据表.xlsx
15班
序号 | 性别 | 数学成绩 |
---|---|---|
1 | 男 | 78 |
2 | 女 | |
3 | 女 | 65 |
4 | 女 | 64 |
5 | 女 | |
6 | 男 | 98 |
7 | 女 | 83 |