import openpyxl
wb = openpyxl.open('files/工作数据.xlsx')
sheet =wb.active #获取活跃表
#提取数据
m_r = sheet.max_row
m_c = sheet.max_column
dict1={}
for r in range(1,m_r+1):
value = sheet.cell(r,6).value
if value not in dict1:
dict1[value] = 1
else:
dict1[value] +=1
# print(dict1)
#饼图数据处理
list1=[]
for key in dict1:
list1.append((key,dict1[key]))
print(list1)
#制作饼状图
from pyecharts import options
from pyecharts.charts import Pie
#制作饼图对象
pie = Pie()
pie.add(
'学历要求',list1,
radius=('20%','80%'),#设置内半径和外半径
# rosetype='radius'
)
#设置全局
pie.set_global_opts(
title_opts=options.TitleOpts(
title='学历要求占比图', #设置标题内容
pos_left='380' #设置对齐距离
),
legend_opts=options.LegendOpts(
is_show=False #关闭图例
)
)
#设置系列
pie.set_series_opts(
label_opts=options.LabelOpts(
formatter='{b}-{d}%' #设置标签格式 {b}名称 {d}占比
)
)
#图像呈现
pie.render('files/学历饼图.html')
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-QeMMxnST-1677069607208)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20230222203751034.png)]
#柱状图处理
from pyecharts.charts import Bar
x_xasix=[]
y_yasix=[]
for key in dict1:
x_xasix.append(key)
y_yasix.append(dict1[key])
bar = Bar()
bar.add_xaxis(x_xasix)
bar.add_yaxis('',y_yasix)
bar.set_global_opts(
toolbox_opts=options.ToolboxOpts(
is_show=True
),
xaxis_opts=options.AxisOpts(
name='学历'
),
yaxis_opts=options.AxisOpts(
name='数量'
)
)
bar.render('files/学历矩形图.html')
ns.AxisOpts(
name=‘数量’
)
)
bar.render(‘files/学历矩形图.html’)
#### 效果图
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-I3YgdJzb-1677069607211)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20230222203930188.png)]