怎么利用Pyecharts可视化微信好友

  介绍

这篇文章主要介绍怎么利用Pyecharts可视化微信好,友文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

<强>前言

最近在研究pyecharts 的用法,它是python的一个可视化工具,然后就想着结合微信来一起玩

不多说,直接看效果:

怎么利用Pyecharts可视化微信好友”> <br/> </p> <p> <img src=

<强>环境配置

pip  install  Pyecharts   pip  install  snapshot_selenium   pip  install  echarts-countries-pypkg   pip  install  echarts-china-provinces-pypkg   pip  install  echarts-china-cities-pypkg   pip  install  echarts-china-counties-pypkg   pip  install  wxpy

<强>获取好友

主要是获取好友基本数据,用来做数据可视化

代码如下:

得到wxpy  import 机器人,聊天      class 演示(聊天):      ,@staticmethod   ,def  get_friend ():=,bot 机器人()=,,friends  bot.friends(更新=True)=,friend_data  []   ,for  friend 朋友:拷贝   if 才能;friend.sex ==, 1:   sex =,才能“男”;   elif 才能;friend.sex ==, 2:   sex =,才能“女”;   其他的才能:   sex 才能=,““   friend_dict 才能=,{   “city"才能:,friend.city,   “province"才能:,friend.province,   “sex"才能:,性爱,   “signature"才能:,friend.signature,      ,,}   friend_data.append才能(friend_dict)      以前,return  friend_data

返回的是微信好友列表,包含好友城市,省份,性别和个性签名等数据。

<>强地理坐标图

地理坐标系组件用于地图的绘制,支持在地理坐标系上绘制散点图,线集。

在pyecharts 中地理坐标图主要是基于地理模块

def  geo_base ():=,,city_data  get_data ()=,geo 地理(init_opts=opts.InitOpts(主题=皏intage"))   ,for  city  city_data拷贝:   ,试一试:   geo.add_schema才能(maptype=癱hina",, itemstyle_opts=opts.ItemStyleOpts(颜色=癵ray"))   geo.add才能(“微信好友分布地图,,,(城市),type_=癳ffectScatter",, symbol_size=10)   geo.set_series_opts才能(label_opts=opts.LabelOpts (is_show=False))   geo.set_global_opts才能(visualmap_opts=opts.VisualMapOpts (),, title_opts=opts.TitleOpts (title=拔⑿藕糜逊植嫉赝肌?,,)   ,except  Exception  as  e:   打印(e)才能   ,通过      ,# geo.render (“geo.html")   ,make_snapshot(司机,geo.render (),“geo.png")

运行完之后会在当前目录生成一个地理。png的图片

怎么利用Pyecharts可视化微信好友

该图片就是微信好友中国分布地图

<>强热力图

热力图也是基于地理模块

唯一的区别在添加函数中类型的为热图

代码如下:

def  heat_map ():=,,city_data  get_data ()=,geo 地理(init_opts=opts.InitOpts(主题=皏intage"))   ,for  city  city_data拷贝:   ,试一试:   geo.add_schema才能(maptype=肮愣?,,itemstyle_opts=opts.ItemStyleOpts(颜色=癵ray"))   geo.add才能(“广东好友热力图,,,(城市),type_=癶eatmap",, symbol_size=10)   geo.set_series_opts才能(label_opts=opts.LabelOpts (is_show=False))   geo.set_global_opts才能(visualmap_opts=opts.VisualMapOpts (),, title_opts=opts.TitleOpts (title=叭攘ν肌?,,toolbox_opts=opts.ToolboxOpts ())   ,except :   ,通过      ,geo.render (“heat.html")

比如可以选择某个省份的数据,运行之后的效果:

怎么利用Pyecharts可视化微信好友

以上就是微信中的广东好友分布热力图

全国分布图

地图是基于地图模块进行扩展

主要用到函数是添加

, def 添加(   ,#系列名称,用于,tooltip 的显示,legend 的图例筛选。   ,series_name: str,      ,#数据项,(坐标点名称,坐标点值)   ,data_pair:序列,      ,#地图类型,具体参考,pyecharts.datasets.map_filenames.json 文件   ,maptype: str =,“china",      ,#是否选中图例   ,is_selected: bool =,真的,      ,#是否开启鼠标缩放和平移漫游。   ,is_roam: bool =,真的,      ,#当前视角的中心点,用经纬度表示   ,中心:可选(序列),=,,      ,#当前视角的缩放比例。   变焦:大敌;可选[数字],=,1,      ,#自定义地区的名称映射   ,name_map:可选的(东西),=,,      ,#标记图形形状   ,象征:可选(str),=,,      ,#是否显示标记图形   ,is_map_symbol_show: bool =,真的,      ,#标签配置项,参考,“series_options.LabelOpts”   ,label_opts:联盟[opts.LabelOpts, dict],=, opts.LabelOpts (),      null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

怎么利用Pyecharts可视化微信好友