You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
796 B

import jieba
import matplotlib.pyplot as plt
from wordcloud import WordCloud
# 读取文本文件
text = open(r"E:\softwareengineer\bulletscreentest\all_content.txt", encoding="utf-8").read()
# 对文本进行分词,默认精确模式
text1=jieba.cut(text)
# 以空格作为分隔符,将分词后的所有字符串合并成一个新的字符串
text = ' '.join(text1)
# 根据分词结果产生词云
wc = WordCloud(font_path = "C:\Windows\Fonts\Microsoft YaHei UI\msyh.ttc",width=500, height=400, mode="RGBA", background_color=None).generate(text)
# 以图片的形式显示词云
plt.imshow(wc, interpolation="bilinear")
# 不显示图像坐标系
plt.axis("off")
# 显示图像
plt.show()
#保存词云图
wc.to_file(r"E:\softwareengineer\bulletscreentest\cloud.png")