From c745130cdd054be56ad20fd1eb8948703dbb4538 Mon Sep 17 00:00:00 2001 From: p7pxq89ba <1552050042@qq.com> Date: Tue, 17 Sep 2024 21:11:38 +0800 Subject: [PATCH] ADD file via upload --- 词云图.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 词云图.py diff --git a/词云图.py b/词云图.py new file mode 100644 index 0000000..d579d0b --- /dev/null +++ b/词云图.py @@ -0,0 +1,36 @@ +import matplotlib.pyplot as plt +from wordcloud import WordCloud + +# 读取包含弹幕数据的文本文件 +with open('爬取的总弹幕.txt', mode='r', encoding='utf-8') as f: + text = f.read() + +# 生成词云图 +wc = WordCloud(font_path='msyh.ttc', # 如果需要支持中文字符,可以指定字体文件路径,例如 'simsun.ttc' + width=800, + height=400, + background_color='white', + + ).generate(text) +wc.to_file('词云图.png') +# 显示词云图 +plt.figure(figsize=(10, 5)) +plt.imshow(wc, interpolation='bilinear') +plt.axis('off') # 隐藏坐标轴 +plt.show() +with open('AI弹幕.txt', mode='r', encoding='utf-8') as f: + text = f.read() + +# 生成词云图 +wc = WordCloud(font_path='msyh.ttc', # 如果需要支持中文字符,可以指定字体文件路径,例如 'simsun.ttc' + width=800, + height=400, + background_color='white', + + ).generate(text) +wc.to_file('AI弹幕.png') +# 显示词云图 +plt.figure(figsize=(10, 5)) +plt.imshow(wc, interpolation='bilinear') +plt.axis('off') # 隐藏坐标轴 +plt.show() \ No newline at end of file