This theme is from Cn|

guangzan

园龄:6年5个月粉丝:676关注:333

2021-10-08 13:41阅读: 62评论: 0推荐: 0

词云

from wordcloud import WordCloud
import matplotlib.pyplot as plt
import jieba

def en_wordcloud():
    with open('1.txt', 'r') as f:
        mytext = f.read()
        print(mytext)

    wordcloud = WordCloud().generate(mytext)

    plt.imshow(wordcloud, interpolation='bilinear')
    plt.axis('off')
    plt.show()


def zh_wordcloud():
    with open('2.txt', 'r', encoding='utf-8') as f:
        text = f.read()

    cut_text = "".join(jieba.cut(text))

    cloud = WordCloud(
        font_path='c:\windows\fonts\stxingka.ttf',
        background_color='white',
        max_words=4000,
        max_font_size=60
    )

    wCloud = cloud.generate(cut_text)
    wCloud.to_file('cloud.jpg')

    plt.imshow(wCloud, interpolation='bilinear')
    plt.axis('off')
    plt.show()


if __name__ == '__main__':
    # en_wordcloud()
    zh_wordcloud()

image

本文作者:guangzan

本文链接:https://www.cnblogs.com/guangzan/p/15379388.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   guangzan  阅读(62)  评论(0编辑  收藏  举报
评论
收藏
关注
推荐
深色
回顶
收起
点击右上角即可分享
微信分享提示