2018-12-16 词云
2018-12-16 本文已影响0人
子小亦大
常规矩形词云
#GovRptWordCloudv1.py
importjieba
importwordcloud
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")
不规则图形词云
#GovRptWordCloudv2.py
importjieba
importwordcloud
fromscipy.misc importimread
mask =imread("chinamap.jpg")
excludes ={ }
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")