Example #1
0
def generate_wordcloud(logo_image,text, stopwords_list, portal, today, path):
    custom_mask = np.array(Image.open(logo_image))

    wordcloud = WordCloud(stopwords = stopwords_list, background_color="white",mask=custom_mask)
    wordcloud.generate(text)


    image_colors = ImageColorGenerator(custom_mask)
    wordcloud.recolor(color_func=image_colors)

    plt.figure(figsize=(10,10))
    plt.imshow(wordcloud, interpolation="bilinear")
    plt.axis("off")
    plt.savefig( path + "/wordclouds/wordcloud_"+portal+"_"+today+".png")
Example #2
0
def make_wc(dict, maskpath="", colours=False):

    if (maskpath):
        word_mask = np.array(Image.open(path.join(d, maskpath)))
        wordcloud = wc(background_color="white", mask=word_mask)

        wordcloud.generate_from_frequencies(dict)

        if (colours):
            image_colours = ImageColorGenerator(word_mask)
            wordcloud.recolor(color_func=image_colours)
    else:
        wordcloud = wc(width=1200, height=800).generate_from_frequencies(dict)

    return wordcloud
Example #3
0
def word_cloud(text):
    """
    Plot a wordcloud using FB CEO congressional hearing text.

    """

    limit = 200
    bgcolor = "#FFFFFF"  # white
    wordcloud = WordCloud(
        max_words=limit,
        #stopwords=english_stopwords,

        # FB Logo souce: https://www.freepik.com/free-icon/facebook-logo_736921.htm
        mask=imread('facebook-logo_318-49940.jpg'),
        background_color=bgcolor,
        collocations=False).generate(text)

    #fig = plt.figure()
    #fig.set_figwidth(14)
    #fig.set_figheight(18)

    fig = plt.gcf()
    fig.set_size_inches(12, 8)

    plt.imshow(wordcloud.recolor(color_func=grey_color, random_state=3),
               interpolation="bilinear")

    plt.axis('off')
    plt.show()

    return wordcloud
Example #4
0
def get_wordcloud(image,font,sw,word,result):
    wordcloud = WordCloud(scale=15, font_path=font, mask=image, stopwords=sw, background_color='white',
                          max_words=80000,max_font_size=10, random_state=42)
    wordcloud.generate(word)
    img_colors = ImageColorGenerator(image)
    plt.imshow(wordcloud.recolor(color_func=img_colors))
    plt.imshow(wordcloud)
    plt.axis('off')
    plt.show()
    wordcloud.to_file(result)
    print('Task Done!')
Example #5
0
    'senast', 'sent', 'sex', 'sextio', 'sextionde', 'sexton', 'sextonde',
    'sig', 'sin', 'sina', 'sist', 'sista', 'siste', 'sitt', 'sju', 'sjunde',
    'sjuttio', 'sjuttionde', 'sjutton', 'sjuttonde', 'sjätte', 'ska', 'skall',
    'skulle', 'slutligen', 'små', 'smått', 'snart', 'som', 'stor', 'stora',
    'stort', 'större', 'störst', 'säga', 'säger', 'sämre', 'sämst', 'så',
    'tack', 'tidig', 'tidigare', 'tidigast', 'tidigt', 'till', 'tills',
    'tillsammans', 'tio', 'tionde', 'tjugo', 'tjugoen', 'tjugoett', 'tjugonde',
    'tjugotre', 'tjugotvå', 'tjungo', 'tolfte', 'tolv', 'tre', 'tredje',
    'trettio', 'trettionde', 'tretton', 'trettonde', 'två', 'tvåhundra',
    'under', 'upp', 'ur', 'ursäkt', 'ut', 'utan', 'utanför', 'ute', 'vad',
    'var', 'vara', 'varför', 'varifrån', 'varit', 'varken', 'varsågod', 'vart',
    'vem', 'vems', 'verkligen', 'vi', 'vid', 'vidare', 'viktig', 'viktigare',
    'viktigast', 'viktigt', 'vilka', 'vilken', 'vilket', 'vill', 'vänster',
    'vänstra', 'värre', 'vår', 'våra', 'vårt', 'än', 'ännu', 'är', 'även',
    'åtminstone', 'åtta', 'åttio', 'åttionde', 'åttonde', 'över', 'övermorgon',
    'överst', 'övre'
]

wordcloud = WordCloud(stopwords=stopwords,
                      background_color="white",
                      mode="RGBA").generate(text)

image_colors = ImageColorGenerator(mask)
plt.figure(figsize=[8, 8])
plt.imshow(wordcloud.recolor(color_func=image_colors),
           interpolation="bilinear")
plt.axis("off")

plt.savefig("blog_irl_cloud.png", dpi=600, facecolor='w', format='png')
plt.show()