流程图(四)利用python绘制漏斗图

流程图(四)利用python绘制漏斗图

漏斗图(Funnel Chart)简介

1

漏斗图经常用于展示生产经营各环节的关键数值变化,以较高的头部开始,较低的底部结束,可视化呈现各环节的转化效率与变动大小。一般重点关注落差较大的环节。

快速绘制

  1. 基于plotly

    # 基本漏斗图
    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()
    

    2

    # 分类漏斗图
    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()
    

    3

  2. 基于pyecharts

    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()
    

    4

    总结

    以上通过plotly、pyecharts快速绘漏斗图。

    共勉~

作者:HsuHeinrich

物联沃分享整理
物联沃-IOTWORD物联网 » 流程图(四)利用python绘制漏斗图

发表回复