0%
python
实现词云
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| 登陆微信获取好友个性签名生成词云 import itchat import jieba import imageio import wordcloud import matplotlib.pyplot as plt
itchat.login() tList=[]
friends=itchat.get_friends(update=True)
for i in friends: signature=i["Signature"] if 'emoji' in signature: pass else: tList.append(signature) text=" ".join(tList)
wordlist_jieba=jieba.lcut(text,cut_all=True) wl_space_split=" ".join(wordlist_jieba)
mk=imageio.imread("/Users/SJCHEN/Downloads/zihaowordcloud-master/code/chinamap.png")
my_wordcloud=wordcloud.WordCloud(background_color='white', width=1000, height=700, font_path='Songti.ttc', max_words=2000, mask=mk, scale=20) my_wordcloud.generate(wl_space_split)
nickname=friends[0]['NickName'] filename="example12-{}的微信好友个性签名词云图.png".format(nickname)
plt.imshow(my_wordcloud) plt.axis("off") plt.show() print('程序结束')
|