zoukankan      html  css  js  c++  java
  • 微信签名生成词云

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

    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()
    
     
     
     
  • 相关阅读:
    QT多个UI文件加入一个项目
    【Go语言】学习资料
    MVC如何在Pipeline中接管请求的?
    ASP.NET MVC路由(5)
    C# dll 事件执行 js 回调函数
    初识Identity
    SpringMVC拦截器
    UrlRouting的理解
    ASP.NET MVC路由
    ASP.NET MVC Module
  • 原文地址:https://www.cnblogs.com/jiadi321/p/10081495.html
Copyright © 2011-2022 走看看