词云——wordcloud
常用功能:
fron_path :在图形中指定的字体,默认不支持中文,需要自己指定
width/height: 长宽
max_word:需要绘制的最多词条数
stopwords:停用词列表
字体设定:
min_font_size:字符大小范围
fron_step:字号增加的步长
relative_sacling:词条频数比例和字号比例的换算关系,默认50%
prefer_horizontal:图中词条水平显示的比例
颜色设定:
background_color:图片背景色
mode:图片颜色编码。如果指定为RGBA,且background_color = None时,背景为透明
color_func:生成新颜色的函数
背景掩膜:
mas:词云使用的背景图
方法
-
生成词云
WordCloud(font_path=myfont).generate(text)
text以空格或者英文符号为分隔符 -
保存图片
to_file(filePath)
3.基于分词频数的绘制
fit_words(频数字典)
使用nltk生成词典
from nltk import FreqDist
FreqDist(分词列表)
词云的展示
import matplotlib.pyplot as plt
plt.axis("off")
plt.imshow(cloudobj)
plt.show()