From 48f287309026004c067b2fdaef79cfc29dd6e1b6 Mon Sep 17 00:00:00 2001 From: ptkbf2lr5 <18759452262@163.com> Date: Wed, 18 Sep 2024 12:30:23 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=8D=E4=BA=91=E5=9B=BE=E7=94=9F=E4=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cloudimage.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 cloudimage.py diff --git a/cloudimage.py b/cloudimage.py new file mode 100644 index 0000000..b7d33e2 --- /dev/null +++ b/cloudimage.py @@ -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=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")