I have found many similar questions and tried several suggestions but nothing seems to work. My plot as shown on screen has too much unneeded whitespace around it, while the image file saved with savefig correctly trims it out.
This is how it's displayed:
while the following is the save image file (and what I'd also like being displayed):
This is my code:
wc = WordCloud(
width=1920, height=1080, max_words=50, background_color="white"
).generate_from_frequencies(dict(data))
# plot
plt.figure(figsize=(10, 10))
plt.imshow(wc, interpolation="bilinear")
plt.axis("off")
fig1 = plt.gcf() # save the current figure
plt.show() # because this generates a new picture
fig1.savefig(
"data/topmentions.png", bbox_inches="tight"
) # bbox_inches="tight" removes white space around the figure
So the question is: How do I get ris of the white space around the wordcloud when showing it on scree, just like what happens in the saved figure?