parent
861ebc750c
commit
dc0e9033bb
@ -1,21 +1,22 @@
|
|||||||
# 导入结巴分词模块
|
# 导入结巴分词模块
|
||||||
import jieba
|
import jieba
|
||||||
# 导入词云图
|
# 导入词云图
|
||||||
import wordcloud
|
import wordcloud
|
||||||
|
|
||||||
# 读取文件内容
|
# 读取文件内容
|
||||||
f = open('弹幕.txt', encoding='utf-8')
|
f = open('弹幕.txt', encoding='utf-8')
|
||||||
txt = f.read()
|
txt = f.read()
|
||||||
print(txt)
|
print(txt)
|
||||||
string = ''.join(jieba.lcut(txt))
|
string = ''.join(jieba.lcut(txt))
|
||||||
print(string)
|
print(string)
|
||||||
wc = wordcloud.WordCloud(
|
# 设置词云图格式
|
||||||
width=1000,
|
wc = wordcloud.WordCloud(
|
||||||
height=1000,
|
width=1000,
|
||||||
background_color='white',
|
height=1000,
|
||||||
# 指定文字
|
background_color='white',
|
||||||
font_path='msyh.ttc',
|
# 指定文字
|
||||||
scale=15,
|
font_path='msyh.ttc',
|
||||||
)
|
scale=15,
|
||||||
wc.generate(string)
|
)
|
||||||
wc.to_file('弹幕词云.png')
|
wc.generate(string) # 生成
|
||||||
|
wc.to_file('弹幕词云.png')
|
||||||
|
Loading…
Reference in new issue