对文字生成自己需要的词云

import wordcloud
import jieba
from imageio import imread 		# imageio引入imread,读取图片

_pict = 'd:\\xxx.jpg'	# 	引入图形
mask = imread(_pict)
_path = 'D:\\xx.txt'	# 引入文本路径
fo = open(_path,'r')
t = fo.read()
fo.close()
text = jieba.lcut(t)
text = ''.join(text)
# print(text)
# 1.设置
w = wordcloud.WordCloud(width=950, height=650, background_color='white', font_path='msyh.ttf', mask=mask)
# 2.加载
w.generate(text)
# 3.输出
w.to_file('02.png')
print('词云已经生成!')

你可能感兴趣的:(python)