python_0">流程图(四)利用python绘制漏斗图
漏斗图(Funnel Chart)简介
漏斗图经常用于展示生产经营各环节的关键数值变化,以较高的头部开始,较低的底部结束,可视化呈现各环节的转化效率与变动大小。一般重点关注落差较大的环节。
快速绘制
-
基于plotly
python"># 基本漏斗图 from plotly import graph_objects as go fig = go.Figure(go.Funnel( y = ["Website visit", "Downloads", "Potential customers", "Requested price", "invoice sent"], x = [39, 27.4, 20.6, 11, 2])) fig.show()
python"># 分类漏斗图 from plotly import graph_objects as go fig = go.Figure() fig.add_trace(go.Funnel( name = 'Montreal', y = ["Website visit", "Downloads", "Potential customers", "Requested price"], x = [120, 60, 30, 20], textinfo = "value+percent initial")) fig.add_trace(go.Funnel( name = 'Toronto', orientation = "h", y = ["Website visit", "Downloads", "Potential customers", "Requested price", "invoice sent"], x = [100, 60, 40, 30, 20], textposition = "inside", textinfo = "value+percent previous")) fig.add_trace(go.Funnel( name = 'Vancouver', orientation = "h", y = ["Website visit", "Downloads", "Potential customers", "Requested price", "invoice sent", "Finalized"], x = [90, 70, 50, 30, 10, 5], textposition = "outside", textinfo = "value+percent total")) fig.show()
-
基于pyecharts
python">from pyecharts import options as opts from pyecharts.charts import Funnel # 自定义数据 x = [39, 27.4, 20.6, 11, 2] y = ["Website visit", "Downloads", "Potential customers", "Requested price", "invoice sent"] c = ( Funnel() .add("商品", [list(z) for z in zip(y, x)]) .set_global_opts(title_opts=opts.TitleOpts(title="基本漏斗图")) ) c.render_notebook()
总结
以上通过plotly、pyecharts快速绘漏斗图。
共勉~