scipy:savefig 没有框架,轴,只有内容 [英] scipy: savefig without frames, axes, only content

查看:16
本文介绍了scipy:savefig 没有框架,轴,只有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 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.

我想避免像 PyPNGscipy.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

推荐答案

EDIT

已将 aspect='normal 更改为 aspect='auto',因为在最新版本的 matplotlib 中发生了变化(感谢 @Luke19).

Changed aspect='normal to aspect='auto' since that changed in more recent versions of matplotlib (thanks to @Luke19).

假设:

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)

然后在其上绘制图像:

ax.imshow(your_image, aspect='auto')
fig.savefig(fname, dpi)

aspect 参数更改像素大小以确保它们填充fig.set_size_inches(…) 中指定的图形大小.要了解如何处理这类事情,请通读 matplotlib 的文档,尤其是在轴、轴和艺术家的主题.

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 没有框架,轴,只有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆