Python pyecharts绘制漏斗图

 

一、pyecharts绘制漏斗图方法简介

funnel.add()方法简介
add(name, attr, value,
funnel_sort="ascending", funnel_gap=0, **kwargs)
name str 图例名称
attr list 属性名称
value list 属性对应的值
funnel_sort str、func
数据排序,可以取ascending,descending,none
funnel_gap int 数据图形间距。默认为0。

二、绘制漏斗图标签显示在内部

attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
value = [20, 40, 60, 80, 100, 120]
funnel = Funnel("漏斗图示例")
funnel.add(
    "商品",
    attr,
    value,
    is_label_show=True,
    label_pos="inside",
    label_text_color="#fff",
)
page.add(funnel)

Python pyecharts绘制漏斗图

 

 三、绘制漏斗图标签显示在外部

#标签显示在外部
funnel2 = Funnel("漏斗图示例", title_pos='center')
funnel2.add(
    "商品",
    attr,
    value,
    is_label_show=True,
    label_pos="outside",
    legend_orient="vertical",
    legend_pos="left",
)
page.add(funnel2)

Python pyecharts绘制漏斗图

 

 四、数据按升序排列

funnel3 = Funnel("漏斗图示例", title_pos='center')
funnel3.add(
    "商品",
    attr,
    value,
    is_label_show=True,
    label_pos="inside",
    legend_orient="vertical",
    legend_pos="left",
    funnel_sort="ascending"
)
page.add(funnel3)

Python pyecharts绘制漏斗图

 

 五、指定图形间隔

funnel4 = Funnel("漏斗图示例", title_pos='center')
funnel4.add(
    "商品",
    attr,
    value,
    is_label_show=True,
    label_pos="inside",
    legend_orient="vertical",
    legend_pos="left",
    funnel_sort="ascending",
    funnel_gap=5,
)
page.add(funnel4)

Python pyecharts绘制漏斗图

 

 六、完整代码如下所示,可直接运行

from pyecharts import Page
from pyecharts import Funnel
page = Page()
#Funnel(漏斗图)
'''
funnel.add()方法简介
add(name, attr, value,
    funnel_sort="ascending", funnel_gap=0, **kwargs)
    name str 图例名称
    attr list 属性名称
    value list 属性对应的值
    funnel_sort str、func
    数据排序,可以取ascending,descending,none
    funnel_gap int 数据图形间距。默认为0。
'''
#标签显示在内部
attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
value = [20, 40, 60, 80, 100, 120]
funnel = Funnel("漏斗图示例")
funnel.add(
    "商品",
    attr,
    value,
    is_label_show=True,
    label_pos="inside",
    label_text_color="#fff",
)
page.add(funnel)

#标签显示在外部
funnel2 = Funnel("漏斗图示例", title_pos='center')
funnel2.add(
    "商品",
    attr,
    value,
    is_label_show=True,
    label_pos="outside",
    legend_orient="vertical",
    legend_pos="left",
)
page.add(funnel2)

#数据按升序排列
funnel3 = Funnel("漏斗图示例", title_pos='center')
funnel3.add(
    "商品",
    attr,
    value,
    is_label_show=True,
    label_pos="inside",
    legend_orient="vertical",
    legend_pos="left",
    funnel_sort="ascending"
)
page.add(funnel3)

#指定图形间隔
funnel4 = Funnel("漏斗图示例", title_pos='center')
funnel4.add(
    "商品",
    attr,
    value,
    is_label_show=True,
    label_pos="inside",
    legend_orient="vertical",
    legend_pos="left",
    funnel_sort="ascending",
    funnel_gap=5,
)
page.add(funnel4)

page.render()

 

上一篇:Python_Pyecharts_无法显示html页面


下一篇:ERROR: Command errored out with exit status 1:安装pip3 install --user pyecharts==0.5.11失败问题总结