我们知道,pyecharts是个非常好的python画图工具包,但是在notebook使用的时候,会遇到图形没法显示的情况,这时候需要做如下设置:
#在程序中添加一下代码,解决pecharts在notebook的依赖
from pyecharts.globals import CurrentConfig, NotebookType
CurrentConfig.NOTEBOOK_TYPE = NotebookType.JUPYTER_NOTEBOOK
举例如下:
import pyecharts.options as opts
from pyecharts.charts import Funnel
#解决echarts在notebook的依赖
from pyecharts.globals import CurrentConfig, NotebookType
CurrentConfig.NOTEBOOK_TYPE = NotebookType.JUPYTER_NOTEBOOK
x_data = ["阅读数", "进入落地页", "报名小白", "购买大课"]
y_data = [350728, 10728, 14091, 1818]
data = [[x_data[i], y_data[i]] for i in range(len(x_data))]
(
Funnel()
.add(
series_name="",
data_pair=data,
gap=2,
tooltip_opts=opts.TooltipOpts(trigger="item", formatter="{a} <br/>{b} : {c}%"),
label_opts=opts.LabelOpts(is_show=True, position="inside"),
itemstyle_opts=opts.ItemStyleOpts(border_color="#fff", border_width=1),
)
.set_global_opts(title_opts=opts.TitleOpts(title="漏斗图", subtitle="阅读->购课"))
.render_notebook()
)
执行代码,输出如下:
这样就OK了。