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