<jupyter_start><jupyter_text>Wordcloud Example<jupyter_code>import wordcloud #pip install wordcloud
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
import urllib

from wordcloud import WordCloud, STOPWORDS
# Read the whole text.
# The Project Gutenberg EBook of <NAME>; or The Whale, by <NAME>
link = "https://www.gutenberg.org/files/2701/2701-0.txt"
urlcontent = urllib.urlopen(link)
text = urlcontent.read()
# read the mask image
pie_mask = np.array(Image.open("mobydick.jpg"))
stopwords = set(STOPWORDS)
stopwords.add("and") #add all the stop words
stopwords.add("chapter")
stopwords.add("upon")
wc = WordCloud(background_color="white", max_words=50, mask=pie_mask, 
               stopwords=stopwords)
# generate word cloud
wc.generate(text)

# store to file
wc.to_file("mobydickwordcloud.jpg")

# show
plt.imshow(wc, interpolation='bilinear')
plt.axis("off")
plt.figure()
#plt.imshow(pie_mask, cmap=plt.cm.gray, interpolation='bilinear')
plt.axis("off")
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12890625, 'fraction_numerical': 0.0107421875, 'mean_word_length': 6.02054794520548, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '189364', 'license': 'MIT', 'n_tokens_mistral': 378, 'n_tokens_neox': 358, 'n_words': 85, 'path': 'WordCloudSample.ipynb', 'repo_name': 'navkesher/wordcloud', 'size': '1036'}