Open cameronaaron opened 4 years ago
Could be similar to this https://github.com/amueller/word_cloud/issues/186 but the solutions that worked for him do not work for me.
You're not saving the wordcloud, but instead you're saving the figure generated by matplotlib, which has white background. Try wordcloud.to_file("wordcloud.png")
You're not saving the wordcloud, but instead you're saving the figure generated by matplotlib, which has white background. Try
wordcloud.to_file("wordcloud.png")
Is there any way to render a transparent output using plt.show() so that it can be copy/pasted with bg transparency? (without having to save to file)
I'm not sure if that's possible with matplotlib, though it could be with the gui interface. Are you using jupyter, and what matplotlib magic are you using? With to_image
it should be possible, though, and with to_svg
it should be possible as well, though I'm failing to make that work right now.
Closing this as the original issue is solved, feel free to open a new issue if to_image
doesn't work for you.
I am working on a project and I need the background of the word cloud to be transparent however even when mode is “RGBA” and background_color is None it results in a white background opposed to a transparent one. I also tried background_color="rgba(255, 255, 255, 0)", mode="RGBA" and get the same result. It needs to be transparent so that the words look like they are floating and you can see through it.
Steps/Code to Reproduce
from wordcloud import WordCloud, STOPWORDS import matplotlib.pyplot as plt text = genes_to_display.summary.values wordcloud = WordCloud( width = 800, height = 600, background_color="rgba(255, 255, 255, 0)", mode="RGBA", stopwords = STOPWORDS).generate(str(text)) fig = plt.figure( figsize = (90, 80), edgecolor = 'k') plt.imshow(wordcloud, interpolation = 'bilinear') plt.axis('off') plt.tight_layout(pad=0) plt.show() plt.savefig("wordcloud.png")
and from wordcloud import WordCloud, STOPWORDS import matplotlib.pyplot as plt text = genes_to_display.summary.values wordcloud = WordCloud( width = 800, height = 600, mode = 'RGBA', background_color = None, stopwords = STOPWORDS).generate(str(text)) fig = plt.figure( figsize = (90, 80), edgecolor = 'k') plt.imshow(wordcloud, interpolation = 'bilinear') plt.axis('off') plt.tight_layout(pad=0) plt.show() plt.savefig("wordcloud.png")
Expected Results
The background should be transparent, not white
Actual Results
I am given a white background opposed to a transparent one
Versions
Python 3.7.7 (default, Mar 10 2020, 15:43:33) [Clang 11.0.0 (clang-1100.0.33.17)] on darwin Type "help", "copyright", "credits" or "license" for more information.