import jieba.analyse
from imageio import imread
from wordcloud import WordCloud
import matplotlib.pyplot as plt
f = open('评论内容1.txt')
content = f.read()
#基于 TF-IDF 算法的关键词抽取,提取了权重最大的30个关键字
tags = jieba.analyse.extract_tags(content,topK=50,withWeight=True)
tags_li = ''
for i in tags:
print(i[0]+' '+str(i[1]))
tags_li=tags_li+i[0]
cut_text =",".join(jieba.cut(tags_li))
jpg = imread('timg.png')
wordcloud = WordCloud(font_path='C:\Windows\Fonts\SIMLI.TTF',
mask=jpg,background_color="white",
width=1500,height=1500).generate(cut_text)
plt.imshow(wordcloud)
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
plt.savefig('词云.jpg',bbox_inches='tight')
plt.show()
评论内容1.txt 链接:https://pan.baidu.com/s/1CblV9rRpyqkgVc8Iz_34Ow
提取码:kqzr