import numpy as np
from PIL import Image
import matplotlib as mpl
import matplotlib.pyplot as plt
from wordcloud import WordCloud, STOPWORDS
stopwords = set(STOPWORDS)
stopwords.add('word')
words = open('words.txt', 'r').read()
new_wc = WordCloud(
background_color='white',
max_words=2000,
stopwords=stopwords
)
new_wc.generate(words)
plt.imshow(new_wc, interpolation='bilinear')
plt.axis('off')
plt.show()
fig = plt.figure()
fig.set_figwidth(14)
fig.set_figheight(18)
plt.imshow(new_wc, interpolation='bilinear')
plt.axis('off')
plt.show()
new_img = np.array(Image.open('image.png'))
new_wc = WordCloud(
background_color='white',
max_words=2000,
mask=new_img,
stopwords=stopwords
)