前言
最近在研究 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=o<mark>来源gaodaimacom搞#^代%!码网</mark>pts.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")