Python词云wordcloud模板

很简单:

import wordcloud
import jieba
import time
start=time.perf_counter()
f=open('xyy.txt','r',encoding='gbk')
#这里的编码格式还不太了解,有的用utf-8,有的用gbk
t=f.read()
f.close()
ls=jieba.lcut(t)
txt=' '.join(ls)
w=wordcloud.WordCloud(font_path='msyh.ttc',width=1000,height=700,stopwords={})
w.generate(txt)
w.to_file('逍遥游.png')
dur=time.perf_counter()-start
print('耗时{0:.2}s'.format(dur))

控制台输出: 耗时7.4s

文件输出:

posted @ 2018-06-24 10:16  永远怀着一颗学习的心  阅读(1155)  评论(0编辑  收藏  举报