Last active
December 12, 2019 03:55
-
-
Save miracleyoo/90f9fb06b8cd22fbeac26d6b3ed59324 to your computer and use it in GitHub Desktop.
[plot wordcloud] #python
This file contains 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
from wordcloud import WordCloud, STOPWORDS | |
# Thanks : https://www.kaggle.com/aashita/word-clouds-of-various-shapes ## | |
def plot_wordcloud(text, mask=None, max_words=200, max_font_size=100, figure_size=(24.0,16.0), | |
title = None, title_size=40, image_color=False): | |
stopwords = set(STOPWORDS) | |
more_stopwords = {'one', 'br', 'Po', 'th', 'sayi', 'fo', 'Unknown'} | |
stopwords = stopwords.union(more_stopwords) | |
wordcloud = WordCloud(background_color='black', | |
stopwords = stopwords, | |
max_words = max_words, | |
max_font_size = max_font_size, | |
random_state = 42, | |
width=800, | |
height=400, | |
mask = mask) | |
wordcloud.generate(str(text)) | |
plt.figure(figsize=figure_size) | |
if image_color: | |
image_colors = ImageColorGenerator(mask); | |
plt.imshow(wordcloud.recolor(color_func=image_colors), interpolation="bilinear"); | |
plt.title(title, fontdict={'size': title_size, | |
'verticalalignment': 'bottom'}) | |
else: | |
plt.imshow(wordcloud); | |
plt.title(title, fontdict={'size': title_size, 'color': 'black', | |
'verticalalignment': 'bottom'}) | |
plt.axis('off'); | |
plt.tight_layout() | |
plot_wordcloud(train_df["question_text"], title="Word Cloud of Questions") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment