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.

38 lines
1021 B

2 months ago
import jieba
import wordcloud
import imageio
from wordcloud import ImageColorGenerator
#读取本地图片
img = imageio.imread('img.png')
#读取保存的弹幕数据
data = open('3.txt',encoding='utf-8')
text = data.read()
#print(text)
#分割词语
word = jieba.lcut(text)
print(word)
#转换为字符串
str = ' '.join(word)
print(str)
# 生成颜色映射
image_colors = ImageColorGenerator(img)
#绘制词云图
wc = wordcloud.WordCloud(
width=800,
height=800,
background_color='white',
mask=img,
contour_color='black',
contour_width=1,
stopwords={'','','','','','','','','','','','','这个','','','','','','','','哈哈哈','不是','就是','',
'真的','','','','','哈哈','哈哈哈哈','还是','没有','','','什么','','',''},
font_path='msyh.ttc'
)
wc.generate(str)
wc.recolor(color_func=image_colors)
wc.to_file("ai词云.png")