wordcloud的github项目:
https://github.com/amueller/word_cloud
其依赖于:matplotlib,pillow,numpy,如果是py2.7需要先确认是否已经安装了这三个包,如果没有,同时使用pip
又安装失败时,需要下载对应的whl,并手动使用以下命令进行安装:
pip install .whl
三个whl文件以及对应的wordcloud.whl已经打包好
代码:
#-*- coding=utf-8 -*-
import jieba
import wordcloud
f = open(r"C:\\Users\\17759\\Desktop\\10000\\wordcloud_data.txt",'rb')
t = f.read()
f.close()
ls = jieba.lcut(t)
txt = ' ' .join(ls)
print txt
#本地字体类型库
font=r'C:\\Windows\\fonts\\msyh.ttf'
w = wordcloud.WordCloud(font_path=font,width = 1000,height = 700,background_color = 'white')
w.generate(txt)
w.to_file(r'C:\Users\\17759\\Desktop\\10000\\grwordcloud.png')
效果图: