From 19e2a4ace4057e28e1cb3053b2010be420f20ec3 Mon Sep 17 00:00:00 2001 From: 965 Date: Tue, 23 May 2023 22:15:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=BB=83=E4=B9=A0=E5=86=85?= =?UTF-8?q?=E5=AE=B9=EF=BC=88=E8=AF=8D=E4=BA=91=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Wordcloud.py | 18 ++++++++++++++++++ temp.py | 17 ----------------- 2 files changed, 18 insertions(+), 17 deletions(-) create mode 100644 Wordcloud.py diff --git a/Wordcloud.py b/Wordcloud.py new file mode 100644 index 0000000..b3c2ff9 --- /dev/null +++ b/Wordcloud.py @@ -0,0 +1,18 @@ +import jieba +import wordcloud +from PIL import Image +import numpy as np + + +raw_data = open("./resources/111.txt", encoding="gbk").read() +ls = jieba.lcut(raw_data) +text = ' '.join(ls) +open("./resources/111.txt", encoding="gbk").close() +mask = np.array(Image.open("./resources/mask.png")) +wc = wordcloud.WordCloud(font_path="msyh.ttc", + mask=mask, + background_color='white', + max_font_size=240, + stopwords={'王勃', '一'}) +wc.generate(text) +wc.to_file("./results/111.png") \ No newline at end of file diff --git a/temp.py b/temp.py index 3ed9bd1..8b13789 100755 --- a/temp.py +++ b/temp.py @@ -1,18 +1 @@ -import jieba -import wordcloud -from PIL import Image -import numpy as np - -raw_data = open("./resources/111.txt", encoding="gbk").read() -ls = jieba.lcut(raw_data) -text = ' '.join(ls) -open("./resources/111.txt", encoding="gbk").close() -mask = np.array(Image.open("./resources/mask.png")) -wc = wordcloud.WordCloud(font_path="msyh.ttc", - mask=mask, - background_color='white', - max_font_size=240, - stopwords={'王勃', '一'}) -wc.generate(text) -wc.to_file("./results/111.png")