Last active
November 7, 2021 23:57
-
-
Save tiaplagata/745478a33d3bd717708412d1acfe6653 to your computer and use it in GitHub Desktop.
function to generate a word cloud from text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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