Last active
June 7, 2022 13:36
-
-
Save Lakshmi-1212/d2d8181f26a8e0b654eb3507069d87f3 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
def create_word_cloud(keywords, maximum_words = 100, bg = 'white', cmap='Dark2', | |
maximum_font_size = 256, width = 3000, height = 2000, | |
random_state = 42, fig_w = 15, fig_h = 10, output_filepath = None): | |
# Convert keywords to dictionary with values and its occurences | |
word_could_dict=Counter(keywords) | |
wordcloud = WordCloud(background_color=bg, max_words=maximum_words, colormap=cmap, | |
stopwords=STOPWORDS, max_font_size=maximum_font_size, | |
random_state=random_state, | |
width=width, height=height).generate_from_frequencies(word_could_dict) | |
plt.figure(figsize=(fig_w,fig_h)) | |
plt.imshow(wordcloud, interpolation="bilinear") | |
plt.axis("off") | |
if output_filepath: | |
plt.savefig(output_filepath, bbox_inches='tight') | |
plt.show() | |
plt.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment