我只想将一个简单的 wordcloud 保存在一个 200x150 像素的文件中,但我得到的是 640x480 像素。我究竟做错了什么?from matplotlib import pyplot as pltfrom wordcloud import WordCloudcloud = WordCloud(width=200,height=150)plt.imshow(cloud.generate_from_frequencies(t))plt.savefig('c.png')plt.clf()
1 回答

慕少森
TA贡献2019条经验 获得超9个赞
为了保存具有确切所需像素数的图形,您可以查看有关指定和保存具有精确大小(以像素为单位)的图形的帖子。
它会给你:
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。例如,您可以通过此链接找到它。
添加回答
举报
0/150
提交
取消