Created
May 25, 2022 08:22
-
-
Save YHaruoka/099e3da16fcb2beb40b88b03d2cd9117 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
from PIL import Image | |
import numpy as np | |
from wordcloud import WordCloud | |
import matplotlib.pyplot as plt | |
mask_array = np.array(Image.open('mask.png')) | |
text = open("test.txt",encoding='utf-8').read() | |
wordcloud_mask = WordCloud(mask=mask_array, background_color="white", max_font_size=250).generate(text) | |
wordcloud_mask.to_file("word_cloud_mask_result.png") | |
wordcloud_mask_contour = WordCloud(mask=mask_array, contour_width=5, contour_color="steelblue", background_color="white", max_font_size=250).generate(text) | |
wordcloud_mask_contour.to_file("word_cloud_mask_contour_result.png") | |
# plt.imshow(wordcloud_mask) | |
plt.imshow(wordcloud_mask_contour) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment