很簡單:
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
文件輸出:
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。