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.
34 lines
1.1 KiB
34 lines
1.1 KiB
2 months ago
|
import jieba
|
||
|
import wordcloud
|
||
|
import imageio
|
||
|
|
||
|
f = open("danmu.txt",encoding = 'utf-8')
|
||
|
text = f.read()
|
||
|
text_list = jieba.lcut(text)
|
||
|
text_str = ' '.join(text_list)
|
||
|
|
||
|
img = imageio.imread('五环.png')
|
||
|
# 制作方形词云图
|
||
|
wc1 = wordcloud.WordCloud(
|
||
|
width=500, # 设置宽度
|
||
|
height=500, # 设置高度
|
||
|
background_color='white', # 设置背景颜色
|
||
|
stopwords={'?', '了', '的', '我', '吗', '是', '这', '都', '啊', '也', '不', '他', '她', '人', '要', '又', '你'},# 屏蔽掉到一些没有意义的词
|
||
|
font_path='msyh.ttc', # 设置字体文件
|
||
|
)
|
||
|
wc1.generate(text_str)
|
||
|
wc1.to_file('WordCloud_1.png')
|
||
|
# 制作五环形状词云图
|
||
|
wc2 = wordcloud.WordCloud(
|
||
|
width = 500, # 设置宽度
|
||
|
height = 500, # 设置高度
|
||
|
background_color = 'white', # 设置背景颜色
|
||
|
mask = img, # 设置形状
|
||
|
stopwords = {'?','了','的','我','吗','是','这','都','啊','也','不','他','她','人','要','又','你'}, # 屏蔽掉到一些没有意义的词
|
||
|
font_path = 'msyh.ttc', # 设置字体文件
|
||
|
)
|
||
|
wc2.generate(text_str)
|
||
|
wc2.to_file('WordCloud_2.png')
|
||
|
|
||
|
|