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")