jieba和词云

Posted modiqiang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jieba和词云相关的知识,希望对你有一定的参考价值。

技术图片
from wordcloud import WordCloud
import matplotlib.pyplot as plt
import jieba
import numpy as np
from PIL import Image
 
 
# 生成词云
def create_word_cloud(filename):
    text = open(r"C:UserslenovoDesktop{}.txt".format(filename),encoding = "utf-8").read()

    wordlist = jieba.cut(text, cut_all=True)
    wl = " ".join(wordlist)
 
    cloud_mask = np.array(Image.open(r"C:UserslenovoDesktop壁纸呗hand drawn of mengyuan04.png"))
 

    wc = WordCloud(

        background_color="black",

        mask=cloud_mask,

        max_words=2000,
        
        font_path=rC:WindowsFontssimhei.ttf,
        height=1200,
        width=1600,
        
        max_font_size=100,
        
        random_state=100,
    )
 
    myword = wc.generate(wl) 
    
    plt.imshow(myword)
    plt.axis("off")
    plt.show()
    wc.to_file(rC:UserslenovoDesktoppy_book.png) 
 
 
if __name__ == __main__:
    create_word_cloud(dicuo)
View Code

技术图片

 

以上是关于jieba和词云的主要内容,如果未能解决你的问题,请参考以下文章

jieba库的分词和词云

jieba库的分词和词云

意境级讲解 jieba分词和词云关键词抽取:TextRankTF-IDF

爬取拉钩岗位信息生成图表和词云

平安喜乐 | Python制作圣诞树和词云

平安喜乐 | Python制作圣诞树和词云