From c69c862d32b7d434abe4e391c3285fd101f9123d Mon Sep 17 00:00:00 2001 From: pnhekgfuf <1913997697@qq.com> Date: Sat, 8 Apr 2023 18:17:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E6=94=BE=E9=A2=98=E8=AF=8D=E4=BA=91?= =?UTF-8?q?=E7=88=AC=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- part1 | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 part1 diff --git a/part1 b/part1 new file mode 100644 index 0000000..ae2895c --- /dev/null +++ b/part1 @@ -0,0 +1,24 @@ +from wordcloud import WordCloud, STOPWORDS +from PIL import Image +import numpy as np +import matplotlib.pyplot as plt +import jieba +# 打开文件 +text = open("2.txt", encoding="utf-8").read() +# 中文分词 +text = ' '.join(jieba.cut(text)) +print(text[:100]) +# 生成对象 +mask = np.array(Image.open("meng.jpg")) # 使用蒙版图片 +wc = WordCloud(mask=mask, + font_path="STKAITI.TTF", + mode="RGBA", + background_color=None, + stopwords=STOPWORDS.add("的") + ).generate(text) +# 显示词云 +plt.imshow(wc, interpolation="bilinear") +plt.axis("off") +plt.show() +#保存文件 +wc.to_file("3.wordcloud3.png")