def generateWordCloud(text):
# read the mask / color image
# taken from http://jirkavinse.deviantart.com/art/quot-Real-Life-quot-Alice-282261010
d = path.dirname(__file__)
cloud_coloring = np.array(Image.open(path.join(d, "us-mask-white.png")))
stopwords = set(STOPWORDS)
stopwords.add("said")
wc = WordCloud(background_color="black", max_words=2000, mask=cloud_coloring,
stopwords=stopwords, max_font_size=40, random_state=42)
# generate word cloud
wc.generate(text)
# create coloring from image
image_colors = ImageColorGenerator(cloud_coloring)
# show
plt.imshow(wc)
plt.axis("off")
plt.show()
评论列表
文章目录