需求:对应政府工作报告等政策文件,如何直观理解?
体会直观的价值:生成词云&优化词云
基本思路:
步骤1:读取文件,分词整理
步骤2:设置并输出词云
步骤3:观察结果,优化迭代
w = wordcloud.WordCloud( \
width = 1000, height = 700,\
background_color = "white", font_path = "msyh.ttc" \
max_words = 15 )
import jieba
import wordcloud
f = open("新时代中国特色社会主义.txt", "r", encoding="utf-8")
t = f.read()
f.close()
ls = jieba.lcut(t)
txt = " ".join(ls)
w = wordcloud.WordCloud( \
width = 1000, height = 700,\
background_color = "white", font_path = "msyh.ttc" )
w.generate(txt)
w.to_file("grwordcloud.png")
import jieba
import wordcloud
from scipy.misc import imread
mask = imread("chinamap.jpg")#加载形状
f = open("新时代中国特色社会主义.txt", "r", encoding="utf-8")
t = f.read()
f.close()
ls = jieba.lcut(t)
txt = " ".join(ls)
w = wordcloud.WordCloud(\
width = 1000, height = 700,\
background_color = "white", font_path = "msyh.ttc", mask = mask
)
w.generate(txt)
w.to_file("grwordcloudm.png")