%load_ext watermark %watermark -d -v -m -p twitter,pyprind,wordcloud,pandas,scipy,matplotlib import sys sys.path.append('../../twitter_timeline/') import twitter_timeline import oauth_info as auth tm = twitter_timeline.TimelineMiner(auth.ACCESS_TOKEN, auth.ACCESS_TOKEN_SECRET, auth.CONSUMER_KEY, auth.CONSUMER_SECRET, auth.USER_NAME ) print('Authentification successful: %s' %tm.authenticate()) tm.get_timeline(max=2000, keywords=[]) tm.df.head() %matplotlib inline import matplotlib.pyplot as plt from wordcloud import WordCloud, STOPWORDS # join tweets to a single string words = ' '.join(tm.df['tweet']) # remove URLs, RTs, and twitter handles no_urls_no_tags = " ".join([word for word in words.split() if 'http' not in word and not word.startswith('@') and word != 'RT' ]) wordcloud = WordCloud( font_path='/Users/sebastian/Library/Fonts/CabinSketch-Bold.ttf', stopwords=STOPWORDS, background_color='black', width=1800, height=1400 ).generate(no_urls_no_tags) plt.imshow(wordcloud) plt.axis('off') plt.savefig('./my_twitter_wordcloud_1.png', dpi=300) plt.show() from scipy.misc import imread twitter_mask = imread('./twitter_mask.png', flatten=True) wordcloud = WordCloud( font_path='/Users/sebastian/Library/Fonts/CabinSketch-Bold.ttf', stopwords=STOPWORDS, background_color='white', width=1800, height=1400, mask=twitter_mask ).generate(no_urls_no_tags) plt.imshow(wordcloud) plt.axis("off") plt.savefig('./my_twitter_wordcloud_2.png', dpi=300) plt.show()