In [1]:
!pip install wordcloud


Collecting wordcloud
  Downloading wordcloud-1.2.1.tar.gz (165kB)
    100% |████████████████████████████████| 174kB 6.3MB/s 
Building wheels for collected packages: wordcloud
  Running setup.py bdist_wheel for wordcloud ... - \ done
  Stored in directory: /home/carlson/.cache/pip/wheels/29/9a/a9/86dcbbd5a7b6ace25887e4351a0136ea6dfcc0dd7de0a51357
Successfully built wordcloud
Installing collected packages: wordcloud
Successfully installed wordcloud-1.2.1

In [5]:
from os import path
from wordcloud import WordCloud



# Read the whole text.
text = "Test, test, beer, bar, test"

# Generate a word cloud image
wordcloud = WordCloud().generate(text)

# Display the generated image:
# the matplotlib way:
import matplotlib.pyplot as plt
plt.imshow(wordcloud)
plt.axis("off")

for i in range(10):
    # take relative word frequencies into account, lower max_font_size
    wordcloud = WordCloud(max_font_size=40, relative_scaling=.5, background_color=None, mode="RGBA").generate(text)
    plt.figure()
    plt.imshow(wordcloud)
    plt.axis("off")
# plt.show()



In [43]:
import pickle
bus_reviews = pickle.load(open('../output/reviews_merged_bus.pickle', 'rb'))
bus_reviews.keys()[0]
import wordcloud

wordcloud = WordCloud(width=200, height=100, prefer_horizontal=1, max_font_size=60, max_words=20, 
                      min_font_size=14, relative_scaling=1, mode="RGBA", background_color=None, 
                      color_func=wordcloud.get_single_color_func("#242426"), stopwords=['bar', "the"]
             ).generate(bus_reviews[u'lLI8ObL8aCVbkrrtAW0EHw'])
plt.figure()
plt.imshow(wordcloud)
plt.axis("off")


Out[43]:
(-0.5, 199.5, 99.5, -0.5)

In [ ]: