Skip to content

Instantly share code, notes, and snippets.

@tiaplagata
Created January 27, 2021 20:55
Show Gist options
  • Save tiaplagata/867601c4f461c0878891b1fe41bbda2a to your computer and use it in GitHub Desktop.
Save tiaplagata/867601c4f461c0878891b1fe41bbda2a to your computer and use it in GitHub Desktop.
create a prettier word cloud with a mask
# A similar function, but using the mask
def generate_better_wordcloud(data, title, mask=None):
cloud = WordCloud(scale=3,
max_words=150,
colormap='RdYlGn',
mask=mask,
background_color='white',
stopwords=stopwords,
collocations=True).generate_from_text(data)
plt.figure(figsize=(10,8))
plt.imshow(cloud)
plt.axis('off')
plt.title(title)
plt.show()
# Use the function with the rome_corpus and our mask to create word cloud
generate_better_wordcloud(rome_corpus, 'Rome, Italy', mask=rome_mask)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment