Last active
September 25, 2021 10:32
-
-
Save Abuton/539b9e91a3367d5a3d5773520de6f247 to your computer and use it in GitHub Desktop.
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 nltk.corpus import stopwords | |
import matplotlib.pyplot as plt | |
from wordcloud import WordCloud | |
def draw_wordcloud(msgs: list): | |
""" | |
Draw wordcloud for visualization of the most used words | |
during conversation | |
args: | |
----- | |
msgs: list: chat content | |
Returns: | |
------- | |
a wordcloud with the most used words having the | |
highest font value | |
""" | |
allWords = ' '.join([twts for twts in msgs]) | |
wordCloud_img = WordCloud(width=500, height=250, random_state=21, | |
max_words=200, mode='RGBA',max_font_size=170, | |
stopwords=wordcloud.STOPWORDS, scale=9, | |
min_word_length=4).generate(allWords) | |
plt.figure(figsize=(20, 12)) | |
plt.imshow(wordCloud_img, interpolation="bilinear") | |
plt.axis('off') | |
plt.tight_layout(); | |
plt.title('most used words', size=20) | |
plt.savefig('wordcloud.jpg') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment