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.
24 lines
692 B
24 lines
692 B
#三、生成词云图
|
|
import jieba
|
|
import wordcloud
|
|
import imageio
|
|
#1.读取弹幕数据
|
|
f =open("总弹幕.txt",encoding='utf-8')
|
|
text =f.read()
|
|
#2.分词
|
|
text_list=jieba.lcut(text)
|
|
text_str=' '.join(text_list)
|
|
#3.词云图
|
|
f2=open("中文常见停用词.text",encoding='utf-8')
|
|
text2=f2.read().splitlines()#读取弹幕
|
|
img= imageio.v2.imread('地球.png')#导入词云形状的图片
|
|
wc=wordcloud.WordCloud(#设置词云格式
|
|
width=1160,#宽
|
|
height=800,#高
|
|
background_color='white',#背景颜色
|
|
mask=img,#云图样式
|
|
stopwords=text2,#禁用词
|
|
font_path='msyh.ttc'#字体
|
|
)
|
|
wc.generate(text_str)
|
|
wc.to_file('词云图(有停用词).png') |