01 | Funnel()
from pyecharts.charts import Funnel
from pyecharts import options as opts
behaviour = ['浏览页面','跳转程序','授权登录','进入游戏','充值消费']
user_counts = [50000,34245,23453,21456,5321]
behaviour_funnel = []
def funnel_model():
funnel = Funnel().set_global_opts(title_opts = opts.TitleOpts(title = "用户行为漏斗模型",subtitle = '分布情况'))
for a in zip(behaviour,user_counts):
behaviour_funnel.append(a)
print(behaviour_funnel)
funnel.add('行为漏斗',behaviour_funnel)
funnel.render('用户行为漏斗模型.html')
funnel_model()
02 | Map( )
from pyecharts.charts import Timeline
time = Timeline()
def gdp_statistics(df):
for i in range(2011,2020):
map_average = Map().add('历年各地区GDP数据',df[['地区',str(i) + '年']].values.tolist(),'china').set_global_opts(
visualmap_opts = opts.VisualMapOpts(is_piecewise=True,pieces=
[
{"min": 0, "max": 10000, "label": "1~10000", "color": "cyan"},
{"min": 10001, "max": 20000, "label": "10001~20000", "color": "yellow"},
{"min": 20001, "max": 50000, "label": "20001~50000", "color": "orange"},
{"min": 50001, "max": 80000, "label": "50001~80000", "color": "coral"},
{"min": 80001, "max": 120000, "label": "80001~120000", "color": "red"},
]
))
time.add(map_average,'{}年'.format(i))
time.render('年度GDP统计.html')
gdp_statistics(df)
03 | Treemap( )
def fans_count(df):
count = df.groupby(['city'])['fans'].agg(['sum'])
count.reset_index(inplace = True)
count = count.sort_values(['sum'],ascending = False).head(20)
fans = []
print(count)
for c,d in zip(count['city'],count['sum']):
data1 = {}
data1['name'] = c
data1['value'] = d
fans.append(data1)
tree_fans = TreeMap(init_opts=opts.InitOpts(width = "1600px", height = "800px")).add('粉丝生态图',fans)
tree_fans.set_global_opts(title_opts=opts.TitleOpts(title="点赞数汇总", pos_left="center", pos_top="5"),
toolbox_opts=opts.ToolboxOpts(is_show=True, feature={"saveAsImage": {}}),
legend_opts=opts.LegendOpts(is_show=False))
tree_fans.render("粉丝数生态分布.html")
fans_count(df)
04 | Line( )
from pyecharts.charts import Line
from pyecharts import options as opts
import os
up_line = Line().add_xaxis(['琴','温迪','钟离'])\
.add_yaxis('up池',[5,77,77])\
.set_global_opts(title_opts = opts.TitleOpts(title ='up池五星'))
up_line.render('up池五星抽卡情况.html'
os.system('explorer.exe /n,D:\pycharm\项目')