In Python's Word Cloud Library, the text color is set randomly. You can set the color theme with colormap, but you cannot set the text to a single color.
First, define a function that returns the text color. In the code below, it is set to white.
word_color_func = lambda *args, **kwargs: "white"
Next, pass the defined function to the argument (color_func) of the WordCloud class.
wordcloud = WordCloud(
color_func = word_color_func,
background_color = "black",
width = 1000,
height = 500,
).generate(text)
With the above, the text color of Word Cloud will be changed as shown in the figure below. The text information passed to WordCloud is Wikipedia's "Machine learning".
You can also set the font color in RGB format. Details can be found at here.
color_func=lambda *args, **kwargs: (255,255,255)
Recommended Posts