python-生成词云图片

import wordcloud
import jieba

f=open("xx.txt","r",encoding="utf-8")
t=f.read()
f.close()
ls=jieba.lcut(t)
txt=" ".join(ls)
w=wordcloud.WordCloud(
	random_state=300,#配色方案数
	width=300,#图片宽度
	height=200,#图片高度
	background_color="white",#背景颜色
	max_words=20,#图片容纳最大词数
	font_path="simfang.ttf"#字体
	)
w.generate(txt)
w.to_file("xx.png")

猜你喜欢

转载自blog.csdn.net/qq_44647926/article/details/89504329