简体   繁体   中英

how to control wordcloud picture size

I just want to save a simple wordcloud in a file 200x150px but am getting 640x480 pixel instead. What am I doing wrong?

from matplotlib import pyplot as plt
from wordcloud import WordCloud
cloud = WordCloud(width=200,height=150)
plt.imshow(cloud.generate_from_frequencies(t))
plt.savefig('c.png')
plt.clf()

In order to save the figure with the exact required number of pixel you can see the post about Specifying and saving a figure with exact size in pixels .

It will give you:

from matplotlib import pyplot as plt
from wordcloud import WordCloud
cloud = WordCloud(width=200/my_dpi,height=150/my_dpi)
plt.imshow(cloud.generate_from_frequencies(t))
plt.savefig('c.png', dpi=my_dpi)
plt.clf()

with the value of my_dpi equal to the dpi of your monitor. You can find it following this link for example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM