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=r‘C: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(r‘C:UserslenovoDesktoppy_book.png‘) if __name__ == ‘__main__‘: create_word_cloud(‘dicuo‘)
以上是关于jieba和词云的主要内容,如果未能解决你的问题,请参考以下文章