Skip to content

Instantly share code, notes, and snippets.

@tiaplagata
Last active November 7, 2021 23:57
Show Gist options
  • Save tiaplagata/745478a33d3bd717708412d1acfe6653 to your computer and use it in GitHub Desktop.
Save tiaplagata/745478a33d3bd717708412d1acfe6653 to your computer and use it in GitHub Desktop.
function to generate a word cloud from text
#Define a list of stop words
stopwords = ['private', 'tour', 'transfer', 'guide', 'skip', 'line',
'skiptheline', 'vice', 'versa']
#A function to generate the word cloud from text
def generate_basic_wordcloud(data, title):
cloud = WordCloud(width=400,
height=330,
max_words=150,
colormap='tab20c',
stopwords=stopwords,
collocations=True).generate_from_text(data)
plt.figure(figsize=(10,8))
plt.imshow(cloud)
plt.axis('off')
plt.title(title, fontsize=13)
plt.show()
#Use the function to generate the word cloud
generate_wordcloud(rome_corpus, 'Rome, Italy')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment