Python word cloud duplicate image and blank file.
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

Function displays 2 plots and saves a blank image. Need on image saved to file.

from wordcloud import WordCloud
import matplotlib.pyplot as plt

def create_word_cloud():
    """ """
    text = "For NOW IS the time, time time,time,time for all" 
    wordcloud = WordCloud().generate(text)
    plt.clf()
    plt.imshow(wordcloud, interpolation='bilinear')
    plt.axis("off")   
    # lower max_font_size
    wordcloud = WordCloud(max_font_size=40).generate(text)
    plt.figure()
    plt.imshow(wordcloud, interpolation="bilinear")
    plt.axis("off")
    plt.show()
    fig1 = plt.gcf()
    filename = "wordcloudtest.png"
    fig1.savefig(filename, dpi=150,bbox_inches='tight')  

create_word_cloud()
Tags
python3

Crowdsource coding tasks.

1 Solution

Winning solution

Solution

Add these two statements after the saveFig function call and it will work fine.

plt.show()

plt.close()

Perfect, thank you!
broadreach 25 days ago
You're welcome! Thank you :)
VladimirMikulic 25 days ago