parent
7ab6a698cb
commit
be9526eba7
@ -0,0 +1,30 @@
|
||||
#软工作业个人————将弹幕文本内容制作成词云图
|
||||
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')
|
Loading…
Reference in new issue