微信签名生成词云

微信签名生成词云

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

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

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()

 

转载于:https://www.cnblogs.com/guobaoyuan/p/9677920.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值