700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > Python - 获取微信好友性别比例( Pie )

Python - 获取微信好友性别比例( Pie )

时间:2023-02-10 09:20:08

相关推荐

Python - 获取微信好友性别比例( Pie )

Counter:计数返回键值的形式

items:将键值对转换为元组

import itchatfrom collections import Counterfrom matplotlib import pyplot as pltplt.rcParams["font.family"]=["sans-serif"]plt.rcParams["font.sans-serif"]=["SimHei"]itchat.auto_login(hotReload=True)friends = itchat.get_friends(update=True)def analyseSex(frinends):sexs = list(map(lambda x:x["Sex"],friends[1:]))counts = list(map(lambda x:x[1],Counter(sexs).items()))labels = ["Male","Unknown","Female"]explode = [0,0,0.1]colors = ["red","yellowgreen","lightskyblue"]plt.pie(counts,explode,labels,colors,radius=0.9,autopct="%.2f%%",shadow = False)plt.legend(loc="upper right")plt.title("%s的微信好友比例" % friends[0]["NickName"])plt.axis("equal")plt.savefig("f:Geclipse的微信好友性别比例.png",dpi=500)plt.show()if __name__=="__main__":analyseSex(friends)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。