按学历对职工人数绘制饼状图,可以读取每个员工的学历,将本科、硕士和博士合并为本科及以上,用python语言
时间: 2024-03-08 10:48:18 浏览: 25
可以使用Python中的matplotlib库绘制饼状图,以下是示例代码:
```python
import matplotlib.pyplot as plt
# 假设有10个员工,其学历分别为本科、硕士、博士、本科、本科、硕士、硕士、博士、本科、硕士
education = ['本科', '硕士', '博士', '本科', '本科', '硕士', '硕士', '博士', '本科', '硕士']
# 统计每种学历的人数
count = {'本科及以上': 0, '博士': 0, '硕士': 0}
for edu in education:
if edu == '本科' or edu == '硕士' or edu == '博士':
count['本科及以上'] += 1
if edu == '博士':
count['博士'] += 1
if edu == '硕士':
count['硕士'] += 1
# 绘制饼状图
labels = ['本科及以上', '博士', '硕士']
sizes = [count['本科及以上'], count['博士'], count['硕士']]
explode = (0, 0.1, 0) # 突出显示博士学历
fig1, ax1 = plt.subplots()
ax1.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%', shadow=True, startangle=90)
ax1.axis('equal') # 保证饼状图是圆形的
plt.show()
```
运行以上代码,即可绘制出按学历对职工人数的饼状图。其中,`education`是存储员工学历的列表,`count`是统计每种学历人数的字典,`labels`是饼状图每个部分的标签,`sizes`是每个部分的大小,`explode`是突出显示博士学历的设置。