I generated this on wordcloud.com using one of the "themes".
I'd like to be able to do this with the python wordcloud library, but so far all I can achieve is a single background color (so all black, not grey and black). Can anyone give me a hint on how to add the additional background color, using matlab or imshow? Here is my code:
import numpy as np
import matplotlib.pyplot as plt
from pathlib import Path
from PIL import Image
from wordcloud import WordCloud
tmp = "some text about Dynasty TV show"
alexis_mask = np.array(Image.open('resources/alexis-poster-3.png'))
print(repr(alexis_mask)) alexis_mask[alexis_mask == 0] = 255
def color_func(word, font_size, position, orientation, random_state=None,
**kwargs):
return "hsl(0, 100%, 27%)"
wc = WordCloud(background_color="black", mask=alexis_mask, max_words=500,contour_width=2, contour_color="black")
wc.generate(tmp)
plt.figure(figsize=(28, 20)) plt.imshow(wc.recolor(color_func=color_func, random_state=3),interpolation="bilinear")
plt.imshow(wc)
I've tried starting with a black/white image, and with a black/white/grey image. So far neither works. I don't think it's offered in the Wordcloud library but is it something I could do using imshow(), after I apply wordcloud? Thanks.