import jieba
from wordcloud import WordCloud
text = (open( r'D:/a.txt', 'r', encoding='gbk')).read()
# 分词,并以空格分割
cut = jieba.cut(text)
string = ' '.join(cut)
wc = WordCloud(
background_color='white',
width=1000,
height=800,
#字体样式,默认是不支持中文的
font_path='C:\windows\Fonts\STZHONGS.TTF',
)
# 绘制图片
wc.generate_from_text(string)
# 保存图片
wc.to_file('1.png')
Wordcloud 词云图
最新推荐文章于 2024-06-16 18:30:53 发布