首页 > 代码库 > Python3制作中文词云图

Python3制作中文词云图

1. 准备好文本数据

2. pip install jieba

3. pip install wordcloud

4. 下载字体例如Songti.ttc(mac系统下的称呼,并将字体放在项目文件夹下)

from os import path
from scipy.misc import imread
import matplotlib.pyplot as plt
import jieba
from wordcloud import WordCloud


text = cleaned_comments #文本数据 cut_text = .join(jieba.lcut(text)) print(cut_text) color_mask = imread("cat.jpg") cloud = WordCloud( font_path=Songti.ttc, # 字体最好放在与脚本相同的目录下,而且必须设置 background_color=white, mask=color_mask, max_words=2000, max_font_size=40 ) word_cloud = cloud.generate(cut_text) plt.imshow(word_cloud) plt.axis(off) plt.show()

运行结果如下:

技术分享

 

参考网址:http://blog.csdn.net/vivian_ll/article/details/68067574

Python3制作中文词云图