pyecharts常用图库

该篇博客介绍了使用Python的pyecharts库进行数据可视化的四个示例:1) 用户行为的漏斗图,展示了从浏览到消费的转化过程;2) 年度各地区GDP的地图展示,通过颜色区分不同经济区间;3) 粉丝点赞数的树状图,展示了前20大城市粉丝的分布;4) 折线图展示了UP池中五星角色的抽卡情况。
摘要由CSDN通过智能技术生成

01 | Funnel()

# 1.导入需要的库和调参模块
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)
#2.Funnel().add('title',data)中,data要为数据集集合
    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) # reset 之后变成新的dataframe,index为0开始,column为city,sum
    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池
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\项目') # 打开所在文件夹
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值