1. 程式人生 > >最簡單中文詞雲圖

最簡單中文詞雲圖

word and via dom htm col tail mask imp

# -*- coding: utf-8 -*-
#author:蔔靈
from wordcloud import WordCloud
import jieba
import matplotlib.pyplot as plt
def draw_wordcloud(text): comment_text = open(text).read() cut_text = " ".join(jieba.cut(comment_text)) cloud = WordCloud( font_path="chinese.ttf", background_color=‘white‘, mask=plt.imread("fu.jpg"), max_words=1000, max_font_size=100, random_state = 30 ) word_cloud = cloud.generate(cut_text) # 產生詞雲 word_cloud.to_file("wordcloud.jpg") #保存圖片 # 顯示詞雲圖片 plt.imshow(word_cloud) plt.axis(‘off‘) plt.show() word_cloud.to_file("wordcloud.jpg") #保存圖片 if __name__ == ‘__main__‘: draw_wordcloud(u‘西遊記.txt‘)

需要的各種模塊就自己下載安裝,還需要準備文件:

.jpg(背景圖片)

.txt(需要生成詞雲的文章)

.ttf(網上down一個中文的字體)

效果圖:

技術分享

背景是女盆友照片,嗯,先醬!

http://blog.csdn.net/vivian_ll/article/details/68067574

https://zhuanlan.zhihu.com/p/20436581?refer=666666 Python word_cloud 部分文檔翻譯 標簽雲系列(二)

http://www.cnblogs.com/lyrichu/p/6151265.html python wordcloud 對電影《我不是潘金蓮》制作詞雲

https://zhuanlan.zhihu.com/p/20436642

最簡單中文詞雲圖