python微信签名生成词云

微信签名生成词云

首先我们需要安装一下模块

pip install wxpy
pip install matplotlib
pip install wordcloud
pip install Pillow
pip install numpy
pip install jieba

上边的模块安装成功后,我们就开始制图了

from wxpy import *
import re
import matplotlib.pyplot as plt
from wordcloud import WordCloud,STOPWORDS
from PIL import Image
import numpy as np
import jieba
'''
想要学习Python?Python学习交流群:1004391443满足你的需求,资料都已经上传群文件,可以自行下载!
''' 
bot=Bot(cache_path=True)
friends=bot.friends()
 
# 统计签名
with open('signatures.txt','w',encoding='utf-8') as f:
    for friend in friends:
        pattern=re.compile(r'[一-龥]+')
        filterdata=re.findall(pattern,friend.signature)
        f.write(''.join(filterdata))
 
abel_mask = np.array(Image.open("chw2.png"))
text_from_file_with_apath = open('signatures.txt',encoding='utf-8').read()
wordlist_after_jieba = jieba.cut(text_from_file_with_apath, cut_all=True)
wl_space_split = " ".join(wordlist_after_jieba)
stopwords = set(STOPWORDS)
wc = WordCloud(background_color="white", margin=5,max_words=2000, mask=abel_mask,
               stopwords=stopwords).generate(wl_space_split)
 
wc.to_file("alice.png")
plt.imshow(wc)
plt.axis("off")
plt.show()

猜你喜欢

转载自blog.csdn.net/fei347795790/article/details/89890709
今日推荐