Created
December 17, 2019 20:16
-
-
Save glickmac/d7674b498caa433db2288e4ba6095f7a 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
with PdfPages('../data/Animal_WordClouds.pdf', "w") as pdf: | |
for item in Chapters: | |
values = text_processing(item) | |
values = [i for i in values if i in animals] | |
y = Counter(values).most_common(1)[0][0] | |
path = "../data/Animals/" + y + ".png" | |
mask = np.array(Image.open(path)) | |
wc = WordCloud(background_color="white", max_words=200, mask=mask, max_font_size=90, random_state=42) | |
titles = "Chapter "+ str(count) + "\n" + "Most Common Animal in Chapter: " + y | |
wc.generate(item) | |
image_colors = ImageColorGenerator(mask) | |
fig = plt.figure(figsize=[7,7]) | |
plt.title(label=titles) | |
plt.imshow(wc.recolor(color_func=image_colors), interpolation="bilinear") | |
plt.axis("off") | |
count += 1 | |
_ = plt.show() | |
pdf.savefig(fig) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment