"""
author:魏振东
data:2019.12.13
func:饼图绘制
"""
import matplotlib.pyplot as plt
import xlrd
x1 = xlrd.open_workbook("软件开发新技术I学生名单.xls")
sheet1 = x1.sheet_by_index(0)
dict1={}
for i in range(1, int(sheet1.nrows)):
if sheet1.cell_value(i,5)=='男':
dict1.setdefault('男', []).append(sheet1.cell_value(i,5))
else:
dict1.setdefault('女', []).append(sheet1.cell_value(i, 5))
man = round(len(dict1['男'])/(len(dict1['男'])+len(dict1['女'])),2)
woman = round(len(dict1['女'])/(len(dict1['男'])+len(dict1['女'])),2)
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
plt.figure(figsize=(6,9))
labels = [u'男',u'女',]
sizes = [man,woman]
colors = ['pink','lightskyblue']
explode = (0.05,0,)
plt.pie(sizes,explode=explode,labels=labels,colors=colors,autopct='%1.2f%%',shadow=True,labeldistance=0.8,startangle=30,radius=1.3,counterclock=False)
plt.axis('equal')
plt.title("Male and female")
plt.legend()
plt.show()