parent
4db4b37a16
commit
6d30d34b44
@ -0,0 +1,20 @@
|
|||||||
|
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=618, height=500, 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")
|
Loading…
Reference in new issue