您现在的位置是:热点 >>正文
看如何用Python数据可视化来分析用户留存率,建议收藏
热点706人已围观
简介...
今天和大家来分享一些数据可视化方向的干货,我们来尝试用Python来绘制一下“漏斗图”,但愿大家在看完本篇文章之后会有所收获。
关于“漏斗图”
漏斗图常用于用户行为的转化率分析,例如通过漏斗图来分析用户购买流程中各个环节的转化率。当然在整个分析过程当中,我们会把流程优化前后的漏斗图放在一起,进行比较分析,得出相关的结论,今天小编就用“matplotlib”、“plotly”以及“pyecharts”这几个模块来为大家演示一下怎么画出好看的漏斗图首先我们先要导入需要用到的模块以及数据,
import matplotlib.pyplot as plt import pandas as pd df = pd.DataFrame({"环节": [看如"环节一", "环节二", "环节三", "环节四", "环节五"], "人数": [1000, 600, 400, 250, 100], "总体转化率": [1何用.00, 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[Pyidx], 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.FontProthperties(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') &onnbsp; # 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]数据, ha='center', fontproperties=font, fontsize=16, color='#2A2A2A') if idx != len(x)-1: next_left = (x_range - x[idx+1])/2 &nbs可视p; shadow_x = [left, next_left, 100-next_left, 100-left, left] shadow_y = [y[idx]-0.4, y[idx+1]+0.4, &化来nbsp; 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', 用户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.LabelOpts率,(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",th建议eme = 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:
相关文章
云计算开发:Python内置函数-oct()函数详解
热点描述 oct() 函数将一个整数转换成 8 进制字符串。 Python2.x 版本的 8 进制以 0 作为前缀表示。 Python3.x 版本的 8 进制以 0o 作为前缀表示。 语法 以下是 oct...
【热点】
阅读更多云计算核心技术Docker教程:Docker开发插件
热点rootfs 目录 该rootfs目录代表插件的根文件系统。在此示例中,它是从 Dockerfile 创建的: 注意:该/run/docker/plugins目录在插件的文件系统中是强制性的,以便 d...
【热点】
阅读更多云计算核心技术Docker教程:Docker Hub设置构建规则
热点默认情况下,设置自动构建时,会为您创建一个基本的构建规则。此默认规则监视master源代码存储库中分支的更改,并将分支构建master为标记为的Docker映像 latest。 在“构建规则”部分中,...
【热点】
阅读更多
热门文章
最新文章
友情链接
- 标签: 康师傅
- https://www.samen-maier.at/search/外推留痕软件【tg:seogoogle987】,7ns
- https://www.kingston.gov.uk/site-search/results/?q=外推留痕软件【tg:seogoogle987】,wkf
- https://www.prattlibrary.org/search?q=外推留痕软件【tg:seogoogle987】,1wL
- https://www.xbiao.com/search/index?tpf&wd=外推留痕软件【tg:seogoogle987】,5ST
- https://www.yr.no/en/search?q=外推留痕软件【tg:seogoogle987】,94f
- https://m.shoppinghow.kakao.com/m/search/q/外推留痕软件【tg:seogoogle987】dAR
- https://www.pmindia.gov.in/en/?s=外推留痕软件【tg:seogoogle987】,ReT
- https://www.tarleton.edu/news/search/外推留痕软件【tg:seogoogle987】,3w6
- https://www.lneg.pt/?cat=140&s=外推留痕软件【tg:seogoogle987】,a1b
- https://hsmoa.com/search?query=外推留痕软件【tg:seogoogle987】dsi
- https://www.usslexington.com/?action=QUERY&s=外推留痕软件【tg:seogoogle987】,mGX
- https://www.nuovabai.it/catalogsearch/result/?action=SEARCH&q=外推留痕软件【tg:seogoogle987】,LV9
- https://www.lauben.com/en/?action=SEARCH&s=外推留痕软件【tg:seogoogle987】,V0h
- https://www.spicebar.de/catalogsearch/result/?q=外推留痕软件【tg:seogoogle987】,3ZI
- https://www.toy-people.com/?s=外推留痕软件【tg:seogoogle987】,ERH
- https://www.sbaad.no/search/外推留痕软件【tg:seogoogle987】,MYj
- https://www.rhymezone.com/r/rhyme.cgi?typeofrhyme=oldrel&loc=nojs&Word=外推留痕软件【tg:seogoogle987】,zLX
- https://www.nyif.com/catalogsearch/result/?q=外推留痕软件【tg:seogoogle987】,72Y
- https://www.duksung.ac.kr/search/front/Search.jsp?qt=外推留痕软件【tg:seogoogle987】cEQ
- https://www.synonyms.com/antonyms/外推留痕软件【tg:seogoogle987】,yWw
- https://www.vfw.org/search-results?q=外推留痕软件【tg:seogoogle987】,eVy
- https://www.sportbiketracktime.com/index.php?route=product/search&tag=外推留痕软件【tg:seogoogle987】,JxK
- https://www.realsporting.com/buscador?buscar=外推留痕软件【tg:seogoogle987】,vRo
- https://www.roberthalf.com/us/en/jobs/all/外推留痕软件【tg:seogoogle987】1dI
- https://www.sdcard.org/ja/?s=外推留痕软件【tg:seogoogle987】,cg4
- https://www.mygrandma.com/Items.aspx?search=外推留痕软件【tg:seogoogle987】,q8k
- https://www.wikiart.org/pt/Search/外推留痕软件【tg:seogoogle987】,3Ff
- https://xn--lgernevedlystskoven-lxb.dk/search/外推留痕软件【tg:seogoogle987】,bqZ
- https://www.springfieldlibrary.org/?s=外推留痕软件【tg:seogoogle987】,dGN
- https://www.sic-info.org/vi/?s=外推留痕软件【tg:seogoogle987】,lWj
- https://www.luxurysociety.com/en/search?q=外推留痕软件【tg:seogoogle987】,c4x
- https://zhidao.baidu.com/index/?action=QUERY&word=外推留痕软件【tg:seogoogle987】,Nso
- https://nicolazzi.it/en/?s=外推留痕软件【tg:seogoogle987】,JRL
- https://store.line.me/search/sticker/ja?q=外推留痕软件【tg:seogoogle987】zBL
- https://www.tahiti-infos.com/search/外推留痕软件【tg:seogoogle987】,g36
- https://www.rockngem.com/?action=CHECK&s=外推留痕软件【tg:seogoogle987】,Xkk
- https://www.reginatangoshoes.com/en/catalogsearch/result/index/?T=1686132113407&q=外推留痕软件【tg:seogoogle987】,HV8
- https://www.unclefossil.com/search/外推留痕软件【tg:seogoogle987】,t2w
- https://www.lyrics.com/lyrics/外推留痕软件【tg:seogoogle987】,vTQ
- https://www.pickett.co.uk/collections/vendors?q=外推留痕软件【tg:seogoogle987】,3zc
- https://www.writingforward.com/?action=SEARCH&s=外推留痕软件【tg:seogoogle987】,PWx
- https://www.nonsolocap.it/cap?action=SEARCH&k=外推留痕软件【tg:seogoogle987】,XWC
- https://www.smarty.net/search?q=外推留痕软件【tg:seogoogle987】,Vke
- https://www.soccerbible.com/search?q=外推留痕软件【tg:seogoogle987】,qOR
- https://www.teacherspayteachers.com/Browse/Price-Range/Free/Search:外推留痕软件【tg:seogoogle987】,4at
- https://www.wellbees.com/catalogsearch/result/?action=CHECK&q=外推留痕软件【tg:seogoogle987】,lwj
- https://www.flickr.com/photos/tags/外推留痕软件【tg:seogoogle987】zfv
- https://www.vietnamconsulate-sf.org/?action=CHECK&s=外推留痕软件【tg:seogoogle987】,DLm
- https://www.pearlstonecenter.org/search/外推留痕软件【tg:seogoogle987】,riA
- https://5gaa.org/?token=6e2l7hjt2i26gzgctgwdrv7v0j6nxorq&s=外推留痕软件【tg:seogoogle987】pB8