• 微信签名生成词云


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

    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()
    
     
     
     
  • 相关阅读:
    axios——post请求时把对象obj数据转为formdata格式
    【工作问题记录】
    如何在Vue项目中使用Element组件
    Manjaro 安装教程
    真 ● 禁秘技 ● 奥义 ● 终端美化
    Docker下MySQL的安装
    Linux Nvidia显卡驱动安装
    Linux下Matlab的安装
    解决SQLPLUS无法使用上下箭头
    @Transactional+@Autowired出现的lateinit property xx has not been initialized错误
  • 原文地址:https://www.cnblogs.com/jiadi321/p/10081495.html
Copyright © 2020-2023  润新知