如果直接from pyecharts import Bar,会发现报错TypeError: 'module' object is not callable,这是因为pyecharts版本更新后,导入模块的方式也变了。
输出html文件
bar.render()
运行代码后,图片会以html文件保存。
from pyecharts.charts import Bar
from pyecharts import options as opts
columns = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
data1 = [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]
data2 = [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3]
bar = (
Bar()
.add_xaxis(columns)
.add_yaxis("降水量", data1)
.add_yaxis("蒸发量", data2)
.set_global_opts(title_opts=opts.TitleOpts(title="一年的降水量与蒸发量"))
)
bar.render()

这篇博客介绍了如何在pyecharts最新版本中正确导入模块并生成柱状图。通过实例展示了在jupyter notebook环境中直接输出图表以及将图表保存为html文件的方法。
最低0.47元/天 解锁文章
1115

被折叠的 条评论
为什么被折叠?



