From 2581a30f93c51f46d1884e15d94a19605a8d66a3 Mon Sep 17 00:00:00 2001 From: pw4izm9rs <2764851313@qq.com> Date: Wed, 18 Sep 2024 10:21:15 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=9F=E6=88=90=E8=AF=8D=E4=BA=91=E5=9B=BE?= =?UTF-8?q?=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- get_wordcloud.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 get_wordcloud.py diff --git a/get_wordcloud.py b/get_wordcloud.py new file mode 100644 index 0000000..d8de295 --- /dev/null +++ b/get_wordcloud.py @@ -0,0 +1,33 @@ +import jieba +import wordcloud +import imageio + +f = open("danmu.txt",encoding = 'utf-8') +text = f.read() +text_list = jieba.lcut(text) +text_str = ' '.join(text_list) + +img = imageio.imread('五环.png') +# 制作方形词云图 +wc1 = wordcloud.WordCloud( + width=500, # 设置宽度 + height=500, # 设置高度 + background_color='white', # 设置背景颜色 + stopwords={'?', '了', '的', '我', '吗', '是', '这', '都', '啊', '也', '不', '他', '她', '人', '要', '又', '你'},# 屏蔽掉到一些没有意义的词 + font_path='msyh.ttc', # 设置字体文件 +) +wc1.generate(text_str) +wc1.to_file('WordCloud_1.png') +# 制作五环形状词云图 +wc2 = wordcloud.WordCloud( + width = 500, # 设置宽度 + height = 500, # 设置高度 + background_color = 'white', # 设置背景颜色 + mask = img, # 设置形状 + stopwords = {'?','了','的','我','吗','是','这','都','啊','也','不','他','她','人','要','又','你'}, # 屏蔽掉到一些没有意义的词 + font_path = 'msyh.ttc', # 设置字体文件 +) +wc2.generate(text_str) +wc2.to_file('WordCloud_2.png') + +