Skip to content

Instantly share code, notes, and snippets.

@tiaplagata
Created January 27, 2021 21:59
Show Gist options
  • Save tiaplagata/bbf6ddfc9d7705dc9345d7eda3a8a6d6 to your computer and use it in GitHub Desktop.
Save tiaplagata/bbf6ddfc9d7705dc9345d7eda3a8a6d6 to your computer and use it in GitHub Desktop.
generate word cloud with basic contour
# Function to generate word cloud with basic contour
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,
contour_color='black',
contour_width=1).generate_from_text(data)
plt.figure(figsize=(10,8))
plt.imshow(cloud)
plt.axis('off')
plt.title(title)
plt.show()
# Use function to generate wordcloud
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