基于excel数据绘制柱状图
from pyecharts.charts import Bar, Pie
from pyecharts import options
# 1.导入数据
wb = openpyxl.open("files/data1.xlsx")
sheet = wb.active
# 学历要求
data = {}
m_r = sheet.max_row
for y in range(2, m_r + 1):
value1 = sheet.cell(y, 8).value
if value1 not in data:
data[value1] = 1
else:
data[value1] += 1
# 构建柱状图
# x轴、y轴数据
x_data = []
y_data = []
for key in data:
x_data.append(key)
y_data.append(data[key])
# 构建柱状图配置
bar = Bar()
bar.add_xaxis(x_data)
bar.add_yaxis("学历要求",
y_data,
color="red",
bar_min_width=40,
bar_max_width=40)
bar.set_global_opts(
title_opts=options.TitleOpts(
title="数据分析岗位学历要求统计",
pos_right=380,
text_align="Center"
),
legend_opts=options.LegendOpts(
is_show=True,
pos_left=30,
item_width=30,
item_height=20,
),
toolbox_opts=options.ToolboxOpts(
is_show=True,
),
datazoom_opts=options.DataZoomOpts(
is_show=True,
),
# x轴的名字
xaxis_opts=options.AxisOpts(
name="学历"
),
# y轴的名字
yaxis_opts=options.AxisOpts(
name="个数"
)
)
# 3.渲染
bar.render("files/学历要求柱状图.html")
展示成果