from wordcloud import WordCloud
with open('test.txt',encoding='utf-8') as file:
# 1.读取文本内容
text=file.read()
#设置词云的背景颜色,宽高,字数
wordcloud=WordCloud(background_color='green',width=600,height=300,max_words=50).generate(text)
#3.生成图片
image=wordcloud.to_image()
#4.显示图片
image.show()
wordcloud.to_file('关键词.png')
制作最简单的词云图
最新推荐文章于 2022-11-02 16:52:31 发布