Skip to content

Instantly share code, notes, and snippets.

@julia-git
Last active December 17, 2019 05:10
Show Gist options
  • Save julia-git/feb6253187b05aa9071c1c0721488f60 to your computer and use it in GitHub Desktop.
Save julia-git/feb6253187b05aa9071c1c0721488f60 to your computer and use it in GitHub Desktop.
generate_wordcloud
from wordcloud import WordCloud, STOPWORDS
from PIL import Image
import urllib
import requests
import numpy as np
import matplotlib.pyplot as plt
words = 'access guest guest apartment area area bathroom bed bed bed bed bed bedroom block coffee coffee coffee coffee entrance entry francisco free garden guest home house kettle kettle kitchen kitchen kitchen kitchen kitchen kitchenliving located microwave neighborhood new park parking place privacy private queen room san separate seperate shared space space space street suite time welcome'
mask = np.array(Image.open(requests.get('http://www.clker.com/cliparts/O/i/x/Y/q/P/yellow-house-hi.png', stream=True).raw))
# This function takes in your text and your mask and generates a wordcloud.
def generate_wordcloud(words, mask):
word_cloud = WordCloud(width = 512, height = 512, background_color='white', stopwords=STOPWORDS, mask=mask).generate(words)
plt.figure(figsize=(10,8),facecolor = 'white', edgecolor='blue')
plt.imshow(word_cloud)
plt.axis('off')
plt.tight_layout(pad=0)
plt.show()
#Run the following to generate your wordcloud
generate_wordcloud(words, mask)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment