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

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

漏斗图(Funnel Chart)简介

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

快速绘制

  1. 基于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()
  2. 基于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快速绘漏斗图。

    共勉~

相关推荐
悦悦子a啊27 分钟前
Python之--基本知识
开发语言·前端·python
笑稀了的野生俊2 小时前
在服务器中下载 HuggingFace 模型:终极指南
linux·服务器·python·bash·gpu算力
Naiva2 小时前
【小技巧】Python+PyCharm IDE 配置解释器出错,环境配置不完整或不兼容。(小智AI、MCP、聚合数据、实时新闻查询、NBA赛事查询)
ide·python·pycharm
路来了3 小时前
Python小工具之PDF合并
开发语言·windows·python
蓝婷儿3 小时前
Python 机器学习核心入门与实战进阶 Day 3 - 决策树 & 随机森林模型实战
人工智能·python·机器学习
AntBlack3 小时前
拖了五个月 ,不当韭菜体验版算是正式发布了
前端·后端·python
.30-06Springfield4 小时前
决策树(Decision tree)算法详解(ID3、C4.5、CART)
人工智能·python·算法·决策树·机器学习
我不是哆啦A梦4 小时前
破解风电运维“百模大战”困局,机械版ChatGPT诞生?
运维·人工智能·python·算法·chatgpt
WJ.Polar4 小时前
Python数据容器-list和tuple
开发语言·python
qq_229644114 小时前
LucidShape 2024.09 最新
python