流程图(四)利用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快速绘漏斗图。

    共勉~

相关推荐
用户27784491049936 小时前
借助DeepSeek智能生成测试用例:从提示词到Excel表格的全流程实践
人工智能·python
JavaEdge在掘金8 小时前
ssl.SSLCertVerificationError报错解决方案
python
我不会编程5558 小时前
Python Cookbook-5.1 对字典排序
开发语言·数据结构·python
老歌老听老掉牙9 小时前
平面旋转与交线投影夹角计算
python·线性代数·平面·sympy
满怀10159 小时前
Python入门(7):模块
python
无名之逆9 小时前
Rust 开发提效神器:lombok-macros 宏库
服务器·开发语言·前端·数据库·后端·python·rust
你觉得2059 小时前
哈尔滨工业大学DeepSeek公开课:探索大模型原理、技术与应用从GPT到DeepSeek|附视频与讲义下载方法
大数据·人工智能·python·gpt·学习·机器学习·aigc
啊喜拔牙9 小时前
1. hadoop 集群的常用命令
java·大数据·开发语言·python·scala
__lost10 小时前
Pysides6 Python3.10 Qt 画一个时钟
python·qt