Pyecharts 是百度 ECharts 的 Python 替身,画出的图不仅美,还能动!
首先安装:pip install pyecharts
from pyecharts.charts import Bar
from pyecharts import options as opts
# 1. 创造画布
bar = Bar()
# 2. 注入灵气 (添加数据)
bar.add_xaxis(["炼气期", "筑基期", "金丹期", "元婴期"])
bar.add_yaxis("弟子人数", [5000, 1000, 200, 50])
# 3. 施加幻术 (设置标题等)
bar.set_global_opts(
title_opts=opts.TitleOpts(title="宗门战力分布图"),
toolbox_opts=opts.ToolboxOpts(), # 开启工具箱
)
# 4. 显形 (生成 HTML)
bar.render("sect_power.html")
运行后会生成一个 HTML 文件,打开它,你就能看到交互式的图表:
Pyecharts 支持多种阵法:
任务:在 Pyecharts 中,生成最终 HTML 文件的方法是什么?