In [1]:
!pip install wordcloud
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]:
In [ ]: