How to perform data analysis with long processes and long cycles? Python makes funnel chart to get

Preface

The text and pictures in this article are from the Internet and are for learning and communication purposes only, and do not have any commercial use. If you have any questions, please contact us for processing.

PS: If you need Python learning materials, you can click on the link below to get it by yourself

Python free learning materials, codes and exchange answers click to join


The funnel diagram is suitable for single-process unidirectional analysis with relatively long business processes, multiple links, and long cycles. Through the comparison of the business data of each link of the funnel, it can intuitively find and explain the link where the problem lies, and then make a decision. The funnel diagram uses a trapezoidal area Indicates the difference between the business volume of a certain link and the previous link. From top to bottom, the funnel diagram has a logical sequence relationship, which shows the completion of business goals as the business process advances.

 

 

For example, when we shop online, the traffic required at different stages is different, so we can use a funnel chart to show this process

1. Basic funnel chart

'''
如有需要Python学习资料的小伙伴可以加群领取:1136201545
'''


from pyecharts import options as opts
from pyecharts.charts import Funnel
x=['浏览网站','加入购物车','下单','支付','完成交易']
y=[8000,3000,2000,800,600]
c = (
    Funnel()
    .add("", [[i,j] for i,j in zip(x,y)])
    .set_global_opts(title_opts=opts.TitleOpts(title="基本漏斗图"))
)
c.render_notebook()

 

The imported data format is a two-dimensional list

Two, inverted funnel chart

from pyecharts import options as opts
from pyecharts.charts import Funnel
x=['浏览网站','加入购物车','下单','支付','完成交易']
y=[8000,3000,2000,1500,1200]
c = (
    Funnel()
    .add("", 
         [[i,j] for i,j in zip(x,y)],
         sort_="ascending",
         label_opts=opts.LabelOpts(position="inside"))
    .set_global_opts(title_opts=opts.TitleOpts(title="基本漏斗图"))
)
c.render_notebook()


add内sort参数可以改变漏斗图的顺序,默认是'descending',表示从大到下;'ascending'表示从小到大;
LabelOpts可以设置标签位置,有以下可选:
'top','left','right','bottom','inside','insideLeft','insideRight'
'insideTop','insideBottom', 'insideTopLeft','insideBottomLeft'
'insideTopRight','insideBottomRight'

Three, set the color and distance of the data graph

from pyecharts import options as opts
from pyecharts.charts import Funnel
x=['浏览网站','加入购物车','下单','支付','完成交易']
y=[8000,3000,2000,800,600]
c = (
    Funnel()
    .add("", 
         [[i,j] for i,j in zip(x,y)],
         color='auto',
         label_opts=opts.LabelOpts(position="top"),
         gap=5
)
    .set_global_opts(title_opts=opts.TitleOpts(title="基本漏斗图"))
)
c.render_notebook()


color='auto'代表颜色自动变化
gap=5代表设置图形间隔

Fourth, set the label display format

from pyecharts import options as opts
from pyecharts.charts import Funnel
x=['浏览网站','加入购物车','下单','支付','完成交易']
y=[8000,3000,2000,800,600]
c = (
    Funnel()
    .add("流量", 
         [[i,j] for i,j in zip(x,y)],
         tooltip_opts=opts.TooltipOpts(trigger="item", 
                                       formatter="{a} <br/>{b} : {c}",
                                       trigger_on="mousemove",  #鼠标移动时触发
                                       is_show=True)
                                       )
    .set_global_opts(title_opts=opts.TitleOpts(title="基本漏斗图"))
)
c.render_notebook()


TooltipOpts参数介绍:
trigger:触发类型,'item'表示数据项图形触发;formatter:标签内容格式器,{a}代表系列名,{b}代表数据名,{c}代表数据值,
是换行符;
trigger_on:提示框触发的条件,'mousemove'代表鼠标移动时触发。

Guess you like

Origin blog.csdn.net/pythonxuexi123/article/details/114933345