pyecharts中的Funnel函數(shù)可以繪制漏斗圖,自動根據(jù)數(shù)據(jù)大小生成由大到小自上而下排列的一個漏斗樣的圖形。
1、導(dǎo)入Funnel模塊。
from pyecharts import Funnel
2、初始化圖形參數(shù)。
funnel = Funnel("漏斗圖", width=600, height=400, title_pos='center')
3、輸入數(shù)據(jù)并繪圖。
funnel.add("商品交易行為記錄數(shù)據(jù)", ['瀏覽','加入購物車','下單','支付','交易成功'], [40000,18000,10000,8500,8000], is_label_show=True,label_formatter='{b} {c}',label_pos="outside",legend_orient='vertical', legend_pos='left')
這里legend_orient、legend_pos分別表示圖例的方向和位置,label_formatter為數(shù)據(jù)標(biāo)簽顯示格式,{a}展示系列名稱,{b}展示數(shù)據(jù)項(xiàng)名稱,{c}展示數(shù)據(jù)項(xiàng)數(shù)值, iwvjtn8m0展示數(shù)值百分比。
4、保存并查看圖形。
funnel.render()
5、顯示百分比。
funnel = Funnel("整體轉(zhuǎn)化率", "圖中的比例表示該行為下的用戶數(shù)占總用戶數(shù)(6萬)的比例",width=600, height=400, title_pos='center')funnel.add("商品交易行為記錄數(shù)據(jù)", ['瀏覽','加入購物車','下單','支付','交易成功'], [int(100*i/60000) for i in [40000,18000,10000,8500,8000]], is_label_show=True,label_formatter='{b} {c}%',label_pos="outside", legend_orient='vertical', legend_pos='left')
注意:這里百分比做了一些處理。而單獨(dú)用iwvjtn8m0展示意義不一樣。
6、保存并展示數(shù)據(jù)。
funnel.render(‘data.html')
新聞熱點(diǎn)
疑難解答
圖片精選