用pyecharts模块可以绘制柱状图 #先导入Jupyter notebook渲染插件
from pyecharts.globals import CurrentConfig, NotebookType
CurrentConfig.NOTEBOOK_TYPE = NotebookType.JUPYTER_NOTEBOOK
#注意区分大小写,如果使用Jupyter Lab 则改为如下代码
#CurrentConfig.NOTEBOOK_TYPE = NotebookType.JUPYTER_LAB
#导入ptecharts,并显示版本
import pyecharts
print(pyecharts.__version__)
#绘图测试
from pyecharts.charts import Bar
from pyecharts import options as opts
#from pyecharts.render import make_snapshot
bar = (
Bar()
.add_xaxis(["衬衫", "毛衣", "领带", "裤子", "风衣", "高跟鞋", "袜子"])
.add_yaxis("商家A", [114, 55, 27, 101, 125, 27, 105])
.add_yaxis("商家B", [57, 134, 137, 129, 145, 60, 49])
.set_global_opts(title_opts=opts.TitleOpts(title="某商场销售情况"))
)
bar.render_notebook()#在Notebook中进行渲染图像
bar.render("1.html")#在本地生成静态网页
#make_snapshot(snapshot, bar.render(), "bar.png")#在本地生成图表截图
|