You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1022011512/软工作业个人————将弹幕文本内容制作成词云图.py

31 lines
698 B

#软工作业个人————将弹幕文本内容制作成词云图
import jieba
import numpy as np
from PIL import Image
from wordcloud import WordCloud
def trans_ch(txt):
words = jieba.lcut(txt)
return ''.join(words)
with open('all_danmaku.txt', 'r', encoding='utf-8') as f:
txt = f.read()
txt = trans_ch(txt)
mask = np.array(Image.open("体育.png").resize((800, 600)))
wordcloud = WordCloud(
background_color="white",
width=800,
height=600,
max_words=200,
max_font_size=80,
mask=mask,
contour_width=4,
contour_color='steelblue',
font_path="msyh.ttf"
).generate(txt)
wordcloud.to_file('弹幕词云图.png')