wordcloud之政府工作报告
2018-05-31 本文已影响11人
爱学习的代代
import jieba
import wordcloud
fo = open("2018年政府工作报告全文.txt","r",encoding= "utf-8")
t = fo.read()
fo.close()
ls = jieba.lcut(t)
str = " ".join(ls)
w = wordcloud.WordCloud(font_path= 'STHeiti Medium.ttc',width= 1000,height= 700,background_color= "white",max_words= 50)
w.generate(str)
w.to_file("18年政府工作报告.png")
mac 上的字体 需要去/System/Library/Fonts路径下 找到汉字字体“STHeiti Medium.ttc”就不会出现乱码的情况了
效果图如下
![](https://img.haomeiwen.com/i1189654/af42ea5f571dd8cf.png)