前言
最近在研究 pyecharts 的用法,它是 python 的一个可视化工具,然后就想着结合微信来一起玩
不多说,直接看效果:
条形图.gif
环境配置
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