python2.7、anaconda2、依赖wordcloud
环境安装就不讲了,自己下吧,就是考验网速。
方法1:使用jupyter的notebook做:网址一篇英文词云,一篇中文词云。
方法2:使用pycharm做,因为我在notebook上一直报找不到wordcloud 这个module,但我本地确实装了wordcloud,所以使用pycharm做。
word_en
from wordcloud import WordCloud
import matplotlib.pyplot as plt
filename = "D:\Projects\demo\yes-minister.txt"
with open(filename) as f:
mytext = f.read()
wordcloud = WordCloud().generate(mytext)
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
plt.show()
word_ch
from wordcloud import WordCloud
import matplotlib.pyplot as plt
import jieba
filename = "D:\Projects\demo\yes_ch.txt"
with open(filename) as f:
mytext = f.read()
mytext = " ".join(jieba.cut(mytext))
print mytext
wordcloud = WordCloud(font_path="font\simsun.ttf").generate(mytext)
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
plt.show()
感觉像是打开了新世界的大门,这个anaconda还有很多好玩的,有兴趣的可以一起多交流,一起耍。