WordCloud学习
class参数
-
font_path:string
使用otf或ttf字体,linux系统上默认是DroidSansMono字体,其他OS请调整。
-
width:int (default=400)
词云画布宽度。
-
height:int (default=200)
词云画布高度。
-
prefer_horizontal:float (default=0.90)
水平拟合。
-
mask:nd-array or None (default=None)
使用掩码图片。
import numpy alice_mask = numpy.array(Image.open(path.join(d, "alice_mask.png")))
-
contour_width: float (default=0)
掩码图片轮廓宽度。
-
contour_color: color value (default=“black”)
掩码轮廓颜色。
-
scale:float (default=1)
绘制大型词云可以使用高比例。
-
min_font_size:int (default=4)
最小字体尺寸。
-
max_font_size:int or None (default=None)
最大字体尺寸。
-
max_words:number (default=200)
词云中包含的最大单词数量。
-
font_step:int (default=1)
-
stopwords:set of strings or None
停用词。没有将使用内置的。使用generate_from_frequencies方法将忽略。
-
background_color:color value (default=“black”)
-
mode:string (default=“RGB”)
-
relative_scaling:float (default=‘auto’) ×××
-
color_func:callable, default=None ×××
-
regexp:string or None (optional) ×××
-
collocations:bool, default=True
是否包含两个单词组成的词组。
-
colormap:string or matplotlib colormap, default=“viridis”
Matplotlib colormap从每个单词中随机绘制颜色。如果指定了“color_func”,则忽略。
-
normalize_plurals:bool, default=True
-
repeat:bool, default=False
方法
-
fit_words
(frequencies)[source]方法generate_from_frequencies的别名。
返回值为WordCloud对象。
-
generate
(text)[source]方法generate_from_text的别名。
返回值为WordCloud对象。
-
generate_from_frequencies
(frequencies, max_font_size=None)[source]根据词和其频率创建词云。参数是键值对为“单词-词频”的字典。
返回值为WordCloud对象。
-
generate_from_text
(text)[source]根据自然语言文本生成词云。如果您传递已经排序的单词列表,则单词将在输出中出现两次。要删除此重复项,请设置collocations = False。
Notes 先调用
process_text
方法,在调用generate_from_frequencies
方法。 -
process_text
(text)[source]将长文本拆分为单词,消除停用词。
返回值为键值对为“单词-词频”的字典。
Notes 也可以使用别的更好的方法来进行单词标记化。
-
recolor
(random_state=None, color_func=None, colormap=None)[source]可以应用新着色修改词云的图。参数:
-
random_state:RandomState, int, or None, default=None
None为固定的随机状态。若为int,则为随机种子。
-
color_func:function or None, default=None
-
colormap:string or matplotlib colormap, default=None
返回值为WordCloud对象。
-
-
to_array
()[source]返回值为numpy数组(width, height, 3)。
-
to_file
(filename)[source]导出为名字是filename的图片。