您现在的位置是:热点 >>正文
看如何用Python数据可视化来分析用户留存率,建议收藏
热点862210人已围观
简介...
今天和大家来分享一些数据可视化方向的干货,我们来尝试用Python来绘制一下“漏斗图”,但愿大家在看完本篇文章之后会有所收获。
关于“漏斗图”
漏斗图常用于用户行为的转化率分析,例如通过漏斗图来分析用户购买流程中各个环节的转化率。当然在整个分析过程当中,我们会把流程优化前后的漏斗图放在一起,进行比较分析,得出相关的结论,今天小编就用“matplotlib”、“plotly”以及“pyecharts”这几个模块来为大家演示一下怎么画出好看的漏斗图首先我们先要导入需要用到的模块以及数据,
import matplotlib.pyplot as plt import pandas as pd df = pd.DataFrame({"环节": [看如"环节一", "环节二", "环节三", "环节四", "环节五"], "人数": [1000, 600, 400, 250, 100], "总体转化率": [1.0何用0, 0.60, 0.40, 0.25, 0.1]})
需要用到的数据如下图所示
用matplotlib来制作漏斗图,制作出来的效果可能会稍显简单与粗糙,制作的原理也比较简单,先绘制出水平方向的直方图,然后利用plot.barh()当中的“left”参数将直方图向左移,便能出来类似于漏斗图的模样
y = [5,4,3,2,1] x = [85,75,58,43,23] x_max = 100 x_min = 0 for idx, val in enumerate(x): plt.barh(y[idPyx], x[idx], left = idx+5) plt.xlim(x_min, x_max)
而要绘制出我们想要的想要的漏斗图的模样,代码示例如下
from matplotlib import font_manager as fm # funnel chart y = [5,4,3,2,1] labels = df["环节"].tolist() x = df["人数"].tolist() x_range = 100 font = fm.FontProperthties(fname="KAITI.ttf") fig, ax = plt.subplots(1, figsize=(12,6)) for idx, val in enumerate(x): left = (x_range - val)/2 plt.barh(y[idx], x[idx], left = left, color='#808B96', height=.8, edgecolor='black') &nonbsp; # label plt.text(50, y[idx]+0.1, labels[idx], ha='center', fontproperties=font, fontsize=16, color='#2A2A2A') # value plt.text(50, y[idx]-0.3, x[idx],&数据nbsp;ha='center', fontproperties=font, fontsize=16, color='#2A2A2A') if idx != len(x)-1: next_left = (x_range - x[idx+1])/2 &可视nbsp; shadow_x = [left, next_left, 100-next_left, 100-left, left] shadow_y = [y[idx]-0.4, y[idx+1]+0.4, 化来 y[idx+1]+0.4, y[idx]-0.4, y[idx]-0.4] plt.plot(shadow_x, shadow_y) plt.xlim(x_min, x_max) plt.axis('off') plt.title('每个环节的流失率', fontproperties=font, loc='center', fontsize=分析24, color='#2A2A2A') plt.show()
绘制出来的漏斗图如下图所示
当然我们用plotly来绘制的话则会更加的简单一些,代码示例如下
import plotly.express as px data = dict(values=[80,73,58,42,23], labels=['环节一', '环节二', '环节三', '环节四', '环节五']) fig = px.funnel(data, y='labels',&n用户bsp;x='values') fig.show()
最后我们用pyecharts模块来绘制一下,当中有专门用来绘制“漏斗图”的方法,我们只需要调用即可
from pyecharts.charts import Funnel from pyecharts import options as opts from pyecharts.globals import ThemeType c = ( Funnel(init_opts=opts.InitOpts(width="900px", height留存="600px",theme = ThemeType.INFOGRAPHIC )) .add( "环节", df[["环节","总体转化率"]].values, sort_="descending", label_opts=opts.LabelOp率,ts(position="inside"), ) .set_global_opts(title_opts=opts.TitleOpts(title="Pyecharts漏斗图", pos_bottom = "90%", pos_left = "center")) ) c.render_notebook()
我们将数据标注上去之后
c = ( Funnel(init_opts=opts.InitOpts(width="900px", height="600px建议",theme = ThemeType.INFOGRAPHIC )) .add( "商品", df[["环节","总体转化率"]].values, sort_="descending", label_opts=opts.LabelOpts(position=收藏"inside"), ) .set_global_opts(title_opts=opts.TitleOpts(title="Pyecharts漏斗图", pos_bottom = "90%", pos_left = "center")) .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}:{c}")) ) c.render_notebook()
Tags:
相关文章
标签: 广汽埃安 OTA锁电 新能源汽车 工信部
热点云梦级5月9日云梦级消息,广汽埃安法务部今日发布声明,针对近期网络上关于公司因 OTA“锁电”问题被立案调查及被约谈的不实信息进行正式辟谣。 声明指出,公司注意到部分网络用户在发布和传播因 OTA(远...
【热点】
阅读更多京东重磅推出国产芯片驱动的 xLLM 推理引擎
热点京东最近宣布了一项令人振奋的技术进展 —— 开源基于国产芯片自主研发的大模型推理引擎 xLLM。这一引擎的推出旨在帮助企业在部署人工智能(AI)应用时,能够以更高的性能和更低的成本运作,进一步推动行业...
【热点】
阅读更多标签: 三六零 360公司 2025财报 网络安全
热点云梦级4月30日云梦级消息,三六零安全科技股份有限公司(公司代码:601360,公司简称:三六零)今日发布2025年的财报。财报显示,360公司2025年营收为86.93亿元,较上年同期的79.48亿...
【热点】
阅读更多
热门文章
最新文章
友情链接
- 标签: 康师傅
- https://www.wilsonart.com/catalogsearch/result/?action=CHECK&q=黑帽seo寄生虫程序【tg:seogoogle987】,sh7
- https://www.military-history.org/?s=黑帽seo寄生虫程序【tg:seogoogle987】,8NQ
- https://yscc1986.net/search/黑帽seo寄生虫程序【tg:seogoogle987】wQp
- https://www.otakuninjahero.com/en/search/黑帽seo寄生虫程序【tg:seogoogle987】,tlb
- https://www.nextavenue.org/?action=QUERY&s=黑帽seo寄生虫程序【tg:seogoogle987】,jtR
- https://www.tombow.com/en/search/黑帽seo寄生虫程序【tg:seogoogle987】,v49
- https://www.youtube.com/hashtag/黑帽seo寄生虫程序【tg:seogoogle987】,kzo
- https://www.lezhin.com/ko/tags/黑帽seo寄生虫程序【tg:seogoogle987】,lHh
- https://www.sonepar.ch/fr/search?q=黑帽seo寄生虫程序【tg:seogoogle987】,WKT
- https://www.partilerdunyasi.com/index.php?route=product/search&tag=黑帽seo寄生虫程序【tg:seogoogle987】,zWS
- https://www.abbreviations.com/黑帽seo寄生虫程序【tg:seogoogle987】499
- https://www.kores.com/?s=黑帽seo寄生虫程序【tg:seogoogle987】,YHK
- https://www.lyrics.com/lyrics/kkk3黑帽seo寄生虫程序【tg:seogoogle987】,KaV
- https://www.tumblr.com/tagged/黑帽seo寄生虫程序【tg:seogoogle987】,giK
- https://www.rotherham.gov.uk/site-search/results/?q=黑帽seo寄生虫程序【tg:seogoogle987】,dfO
- https://www.teamlab.art/pt/?submit=黑帽seo寄生虫程序【tg:seogoogle987】,f3X
- https://www.roberthalf.com/us/en/jobs/all/黑帽seo寄生虫程序【tg:seogoogle987】vz4
- https://www.udc.co.uk/index.php?route=product/search&sort=p.price&order=DESC&tag=黑帽seo寄生虫程序【tg:seogoogle987】,Lf4
- https://www.madebyoranges.com/nl/search/黑帽seo寄生虫程序【tg:seogoogle987】,ICw
- https://hsmoa.com/search?query=黑帽seo寄生虫程序【tg:seogoogle987】j58
- https://www.tcv.org.uk/search/黑帽seo寄生虫程序【tg:seogoogle987】,wks
- https://www.lgnewsroom.com/search/黑帽seo寄生虫程序【tg:seogoogle987】,LuD
- https://www.kyuhoshi.com/?s=黑帽seo寄生虫程序【tg:seogoogle987】,D8n
- https://www.mingwai.edu.hk/?langzh-hant&s=黑帽seo寄生虫程序【tg:seogoogle987】,ZCm
- https://www.xvideos.com/tags/黑帽seo寄生虫程序【tg:seogoogle987】,n0V
- https://www.polliwogs.com/search/黑帽seo寄生虫程序【tg:seogoogle987】,7of
- https://www.rockngem.com/?action=CHECK&s=黑帽seo寄生虫程序【tg:seogoogle987】,2ke
- https://www.libros.unam.mx/catalogsearch/result/?cat=37&dir=asc&format=20&lit=20&manufacturer=3230&mode=list&order=year_edition&q=黑帽seo寄生虫程序【tg:seogoogle987】,wJo
- https://www.klatreverden.no/search?q=黑帽seo寄生虫程序【tg:seogoogle987】,RlM
- https://www.navylookout.com/?ID=nSBR6Ivdu6lZg1yr2SDs30Lo5sTs76yJ&s=黑帽seo寄生虫程序【tg:seogoogle987】,pdc
- https://www.kingston.gov.uk/site-search/results/?q=黑帽seo寄生虫程序【tg:seogoogle987】,gPW
- https://www.qylaws.com/search/黑帽seo寄生虫程序【tg:seogoogle987】,vwr
- https://www.hanbat.ac.kr/search/front/Search.jsp?qt=黑帽seo寄生虫程序【tg:seogoogle987】Ywx
- https://www.polar-tech.com/?action=QUERY&s=黑帽seo寄生虫程序【tg:seogoogle987】,s5u
- https://www.kubb-tool.bfs.admin.ch/en/search?action=CHECK&q=黑帽seo寄生虫程序【tg:seogoogle987】,vkK
- https://www.nyif.com/catalogsearch/result/?q=黑帽seo寄生虫程序【tg:seogoogle987】,LHk
- https://www.lee.com/search?q=黑帽seo寄生虫程序【tg:seogoogle987】,hxV
- https://www.usslexington.com/?action=QUERY&s=黑帽seo寄生虫程序【tg:seogoogle987】,K5o
- https://www.thealexandrian.net/?s=黑帽seo寄生虫程序【tg:seogoogle987】,w8H
- https://www.flickr.com/photos/tags/黑帽seo寄生虫程序【tg:seogoogle987】KkU
- https://www.jusoen.com/addreng.asp?p1=黑帽seo寄生虫程序【tg:seogoogle987】J8u
- https://www.teamlab.art/zh-hans/?submit=黑帽seo寄生虫程序【tg:seogoogle987】,gxI
- https://www.welshmountainzoo.org/shop/index.php?routeproduct/search&tag=黑帽seo寄生虫程序【tg:seogoogle987】,GY5
- https://www.solerpalau.com/en-en/catalogsearch/result/?q=黑帽seo寄生虫程序【tg:seogoogle987】,C00
- https://www.tarleton.edu/?s=黑帽seo寄生虫程序【tg:seogoogle987】,ARD
- https://www.l-and-b.jp/?page=1&s=黑帽seo寄生虫程序【tg:seogoogle987】,tGh
- https://www.abbreviations.com/黑帽seo寄生虫程序【tg:seogoogle987】J6f
- https://www.smarty.net/search?q=黑帽seo寄生虫程序【tg:seogoogle987】,Q66
- https://www.qidulp.com/search?query=黑帽seo寄生虫程序【tg:seogoogle987】,F4V
- https://www.metaltix.com/?view=tours&filter=search&q=黑帽seo寄生虫程序【tg:seogoogle987】,5rZ