问题描述
在numpy / scipy中,我有一个存储在数组中的图像。我可以显示它,我想使用 savefig
保存它,不带任何边框,轴,标签,标题,......只是纯粹的图像,没什么否则。
In numpy/scipy I have an image stored in an array. I can display it, I want to save it using savefig
without any borders, axes, labels, titles,... Just pure image, nothing else.
我想避免像 PyPNG
或 scipy.misc.imsave
,它们有时会出现问题(它们并不总是安装好,只有基本的 savefig()
对我来说
I want to avoid packages like PyPNG
or scipy.misc.imsave
, they are sometimes problematic (they do not always install well, only basic savefig()
for me
推荐答案
假设:
import matplotlib.pyplot as plt
制作没有框架的数字:
fig = plt.figure(frameon=False)
fig.set_size_inches(w,h)
使内容填满整个数字
ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_off()
fig.add_axes(ax)
然后绘制你的图像在它上面:
Then draw your image on it :
ax.imshow(your_image, aspect='normal')
fig.savefig(fname, dpi)
方面
参数更改像素大小以确保它们填充 fig.set_size_inches(...)
中指定的图形大小。要了解如何使用此类内容,请阅读,尤其是Axes,Axis和Artist的主题。
The aspect
parameter changes the pixel size to make sure they fill the figure size specified in fig.set_size_inches(…)
. To get a feel of how to play with this sort of things, read through matplotlib's documentation, particularly on the subject of Axes, Axis and Artist.
这篇关于scipy:savefig没有框架,轴,只有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!