Last active
January 28, 2021 14:51
-
-
Save tiaplagata/7d009231839aa514b01eb33576235138 to your computer and use it in GitHub Desktop.
Use mask colors to recolor wordcloud
This file contains hidden or 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 wordcloud import ImageColorGenerator | |
#Create the mask | |
colosseum_mask = np.array(Image.open('/Users/tiaplagata/Downloads/colosseum.jpg')) | |
#Grab the mask colors | |
colors = ImageColorGenerator(colosseum_mask) | |
#Instantiate the wordcloud using color_func argument | |
cloud = WordCloud(mask=colosseum_mask, | |
background_color='white', | |
color_func=colors).generate_from_text(data) | |
#Plot the wordcloud | |
plt.figure(figsize=(10,8)) | |
plt.imshow(cloud) | |
plt.axis('off') | |
plt.title(title) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment