1-获取微信好友地域分布

效果

依赖

该demo需要下载两个依赖模块:

pip install wxpy==0.3.9.8
pip install echarts-countries-pypkg==0.1.6
pip install pyecharts_snapshot==0.2.0   # 下载失败:pip install -i https://pypi.doubanio.com/simple/ pyecharts_snapshot
pip install echarts-countries-pypkg==0.1.6  # 全球国家地图
pip install echarts-china-provinces-pypkg==0.0.3   # 中国省级地图
pip install echarts-china-cities-pypkg==0.0.9    # 中国市级地图

注意,别忘了下载地图.......

代码示例

from wxpy import *
from pyecharts import Map
import webbrowser
bot = Bot()
friends = bot.friends()
area_dic = {}  # 定义一个字典,用来存放省市以及省市人数
for friend in friends:
    # friend.province  # 所在省份
    # friend.city  # 所在城市
    print(friend, friend.province)
    if friend.province not in area_dic:
        area_dic[friend.province] = 1
    else:
        area_dic[friend.province] += 1
attr = area_dic.keys()
value = area_dic.values()
map = Map("%s 朋友们的地域分布" % bot.self.name, width=1200, height=600)
map.add(
    "好友地域分布",
    attr,
    value,
    maptype='china',
    # maptype='world',
    is_visualmap=True,  # 结合体VisualMap
)   # 图表名称str,属性名称list,属性所对应的值list, 
# is_visualmap -> bool 是否使用视觉映射组件
map.render('area.html')
webbrowser.open("area.html")
posted @ 2019-03-01 09:40  听雨危楼  阅读(1000)  评论(0编辑  收藏  举报