Esempio n. 1
0
def show_cloud(words):
    d = {}
    for a, x in words:
        d[a] = x

    import matplotlib.pyplot as plt
    from wordcloud import WordCloud

    wordcloud = WordCloud()
    wordcloud.prefer_horizontal = 1
    wordcloud.width = 800
    wordcloud.height = 800
    wordcloud.background_color = 'white'
    wordcloud.generate_from_frequencies(frequencies=d)

    plt.figure(figsize=(8, 8), facecolor=None)
    plt.imshow(wordcloud.recolor(color_func=grey_color_func, random_state=3),
               interpolation="bilinear")
    plt.axis("off")
    plt.show()
Esempio n. 2
0
                    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
image_size = image.size
new_size = tuple(map(operator.add, image.size, (200, 200)))
new_img = Image.new("RGB", new_size, "white")
pos = tuple(map(operator.sub, new_size, image_size))