我只想将一个简单的单词云保存在200x150px的文件中,但得到的是640x480像素。我做错了什么?
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()发布于 2019-02-22 05:31:29
为了用精确的像素数保存图形,您可以查看关于Specifying and saving a figure with exact size in pixels的帖子。
它将为您提供:
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()使my_dpi的值等于监视器的dpi。例如,您可以在此link下面找到它。
https://stackoverflow.com/questions/54816179
复制相似问题