内容简介:最近在研究主要是获取好友基本数据,用来做数据可视化 代码如下:地理坐标系组件用于地图的绘制,支持在地理坐标系上绘制散点图,线集。
最近在研究 pyecharts 的用法,它是 python 的一个可视化工具,然后就想着结合微信来一起玩 不多说,直接看效果:
环境配置
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 复制代码
获取好友
主要是获取好友基本数据,用来做数据可视化 代码如下:
from wxpy import Bot, Chat class Demo(Chat): @staticmethod def get_friend(): bot = Bot() friends = bot.friends(update=True) friend_data = [] for friend in friends: if friend.sex == 1: sex = "男" elif friend.sex == 2: sex = "女" else: sex = "" friend_dict = { "city": friend.city, "province": friend.province, "sex": sex, "signature": friend.signature, } friend_data.append(friend_dict) return friend_data 复制代码
地理坐标图
地理坐标系组件用于地图的绘制,支持在地理坐标系上绘制散点图,线集。
在 pyecharts 中地理坐标图主要是基于 Geo 模块
def geo_base(): city_data = get_data() geo = Geo(init_opts=opts.InitOpts(theme="vintage")) for city in city_data: try: geo.add_schema(maptype="china", itemstyle_opts=opts.ItemStyleOpts(color="gray")) geo.add("微信好友分布地图", [city], type_="effectScatter", 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: print(e) pass # geo.render("geo.html") make_snapshot(driver, geo.render(), "geo.png") 复制代码
运行完之后会在当前目录生成一个 geo.png 的图片
热力图
热力图也是基于 Geo 模块 唯一的区别在 add 函数中 type 的为 heatmap
代码如下:
def heat_map(): city_data = get_data() geo = Geo(init_opts=opts.InitOpts(theme="vintage")) for city in city_data: try: geo.add_schema(maptype="广东", itemstyle_opts=opts.ItemStyleOpts(color="gray")) geo.add("广东好友热力图", [city], type_="heatmap", 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 : pass geo.render("heat.html") 复制代码
运行之后的效果:
全国分布图
地图是基于 Map 模块进行扩展 主要用到函数是 add
def add( # 系列名称,用于 tooltip 的显示,legend 的图例筛选。 series_name: str, # 数据项 (坐标点名称,坐标点值) data_pair: Sequence, # 地图类型,具体参考 pyecharts.datasets.map_filenames.json 文件 maptype: str = "china", # 是否选中图例 is_selected: bool = True, # 是否开启鼠标缩放和平移漫游。 is_roam: bool = True, # 当前视角的中心点,用经纬度表示 center: Optional[Sequence] = None, # 当前视角的缩放比例。 zoom: Optional[Numeric] = 1, # 自定义地区的名称映射 name_map: Optional[dict] = None, # 标记图形形状 symbol: Optional[str] = None, # 是否显示标记图形 is_map_symbol_show: bool = True, # 标签配置项,参考 `series_options.LabelOpts` label_opts: Union[opts.LabelOpts, dict] = opts.LabelOpts(), # 提示框组件配置项,参考 `series_options.TooltipOpts` tooltip_opts: Union[opts.TooltipOpts, dict, None] = None, # 图元样式配置项,参考 `series_options.ItemStyleOpts` itemstyle_opts: Union[opts.ItemStyleOpts, dict, None] = None, ) 复制代码
代码如下:
def map_base(): province_data = province_list() maps = Map() maps.add("", province_data, "china") maps.set_global_opts(title_opts=opts.TitleOpts(title="微信好友分布图"), visualmap_opts=opts.VisualMapOpts()) make_snapshot(driver, geo.render(), "map.png") 复制代码
词云图
好友城市分布词云图
c = ( WordCloud() .add("", city_list, word_size_range=[15, 50], shape="diamond", word_gap=10) .set_global_opts(title_opts=opts.TitleOpts(title="diamond")) ) make_snapshot(driver, c.render(), "world.png") 复制代码
效果如下:
条形图
先来看下效果:
代码如下:
def bar_datazoom_slider() -> Bar: city_data = get_data() c = ( Bar(init_opts=opts.InitOpts(page_title="条形图")) .add_xaxis([city[0] for city in city_data]) .add_yaxis("城市人数", [city[1] for city in city_data]) .set_global_opts( title_opts=opts.TitleOpts(title="好友城市分布条形图"), datazoom_opts=[opts.DataZoomOpts(orient="vertical")] ) ) return c 复制代码
最后,再提供大家微信头像另一种好玩的方式:
先看图:
除此之外,还能定制文字,将自己想制作的文字,输入即可!
后台回复 "image" 即可获取源码
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- 利用Python网络爬虫抓取微信好友的签名及其可视化展示
- 微博 Qzone 微信 利用Python网络爬虫抓取微信好友的所在省位和城市分布及其可视化
- itchat 保存好友信息以及生成好友头像图片墙
- 如何利用Python网络爬虫抓取微信好友数量以及微信好友的男女比例
- 微信好友大揭秘,使用Python抓取朋友圈数据,通过人脸识别全面分析好友,一起看透你的“朋友圈”
- websocket 实战——好友聊天
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Rework
Jason Fried、David Heinemeier Hansson / Crown Business / 2010-3-9 / USD 22.00
"Jason Fried and David Hansson follow their own advice in REWORK, laying bare the surprising philosophies at the core of 37signals' success and inspiring us to put them into practice. There's no jarg......一起来看看 《Rework》 这本书的介绍吧!
随机密码生成器
多种字符组合密码
html转js在线工具
html转js在线工具