import jieba
import wordcloud
f=open("tanhualin1.txt","r",encoding="utf-8")
t=f.read()
f.close()
ls=jieba.lcut(t)
txt="".join(ls)
w=wordcloud.WordCloud(font_path="msyh.ttc", width=1000, height=700, background_color="white")
w.generate(txt)
w.to_file("grwordcloud.png")
代码如上,先要通过cmd在python上安装jieba库和wordcloud库蛤,直接在后面输入pip install jieba就可以了(wordcloud同样)
导入后代码的步骤解释
最后的结果如图: