很简单:
import wordcloudimport jiebaimport timestart=time.perf_counter()f=open('xyy.txt','r',encoding='gbk')#这里的编码格式还不太了解,有的用utf-8,有的用gbkt=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()-startprint('耗时{0:.2}s'.format(dur))
控制台输出: 耗时7.4s
文件输出: