From dc0e9033bbe27916dae435de63189a47aba93c41 Mon Sep 17 00:00:00 2001 From: pff5ls68k <1822218970@qq.com> Date: Fri, 13 Sep 2024 15:18:15 +0800 Subject: [PATCH] =?UTF-8?q?Update=20=E8=AF=8D=E4=BA=91.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 词云.py | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/词云.py b/词云.py index 0005aa6..906b4d4 100644 --- a/词云.py +++ b/词云.py @@ -1,21 +1,22 @@ -# 导入结巴分词模块 -import jieba -# 导入词云图 -import wordcloud - -# 读取文件内容 -f = open('弹幕.txt', encoding='utf-8') -txt = f.read() -print(txt) -string = ''.join(jieba.lcut(txt)) -print(string) -wc = wordcloud.WordCloud( - width=1000, - height=1000, - background_color='white', - # 指定文字 - font_path='msyh.ttc', - scale=15, -) -wc.generate(string) -wc.to_file('弹幕词云.png') +# 导入结巴分词模块 +import jieba +# 导入词云图 +import wordcloud + +# 读取文件内容 +f = open('弹幕.txt', encoding='utf-8') +txt = f.read() +print(txt) +string = ''.join(jieba.lcut(txt)) +print(string) +# 设置词云图格式 +wc = wordcloud.WordCloud( + width=1000, + height=1000, + background_color='white', + # 指定文字 + font_path='msyh.ttc', + scale=15, +) +wc.generate(string) # 生成 +wc.to_file('弹幕词云.png')