示例#1
0
def generate_word_cloud(word_text, stopword_list=list(), is_chinese=False):
    stopword_set = set(STOPWORDS)
    for item in stopword_list:
        stopword_set.add(item)
    word_cloud = WordCloud(
        # mask=np.array(Image.open('assert/background.png')),
        stopwords=stopword_set,
        width=1000,
        height=618,
        max_words=3000,
        prefer_horizontal=0.99,
        # random_state=2333
        # max_font_size=200,
        background_color='#EEEEEE',
    )
    if is_chinese:
        word_cloud.font_path = '../assert/msyh.ttf'
        word_cloud.max_words = 1000
        word_text = ' '.join(jieba.cut(word_text))
    word_cloud.generate(word_text)
    return word_cloud
示例#2
0
def grey_color_func(word,
                    font_size,
                    position,
                    orientation,
                    random_state=None,
                    **kwargs):
    return "hsl(0, 0%%, %d%%)" % (80 + font_size / 3)


mask = np.array(Image.open(mask_path))
image_color = ImageColorGenerator(mask)
text = open(data_path).read()

#word cloud settings
wc = WordCloud(font_path=content_font_path)
wc.max_words = 500
wc.background_color = "#FFFFFF"
wc.min_font_size = 7
wc.scale = 5
wc.prefer_horizontal = 1
wc.mode = 'RGBA'
wc.mask = mask

#wc creation
wc = wc.generate(text)
default_colors = wc.to_array()
wc.recolor(color_func=image_color, random_state=3)

image = wc.to_image()

#add border
示例#3
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from wordcloud import WordCloud

wc = WordCloud(mask=mask, background_color='white')
wc.max_words=2000
wc.fit_words(tuple_dict)
wc.to_file(r.wordcloud_output_path)