ADD file via upload

main
piw4f8lbj 2 months ago
parent 6034af7908
commit 77cfc4c22e

@ -0,0 +1,28 @@
import jieba
import wordcloud
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
def make_wordcloud():
# 打开弹幕文件
with open('paris_olympics_danmaku.txt', 'r', encoding='utf-8') as f:
text = f.read()
# 使用 jieba 进行分词
words = jieba.lcut(text)
new_text = " ".join(words)
# 打开背景图片
mask = np.array(Image.open('background.jpg'))
# 创建词云对象
wc = wordcloud.WordCloud(font_path='simhei.ttf', mask=mask, background_color='white')
# 生成词云
wc.generate(new_text)
# 显示词云图
plt.imshow(wc, interpolation='bilinear')
plt.axis('off')
plt.show()
Loading…
Cancel
Save