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)