在python中使用子图和imshow时删除白色边框(Matplotlib) [英] Remove white border when using subplot and imshow in python (Matplotlib)
本文介绍了在python中使用子图和imshow时删除白色边框(Matplotlib)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
import numpy as np
import sys
import matplotlib as mpl
import matplotlib.pyplot as plt
我使用以下代码保存图像
i use the following code to save an image
fig, ax = plt.subplots(frameon=False)
ax.axis ('off')
ax.imshow (array[:,:,0,0,0])
fig.savefig ("file.png", bbox_inches='tight')
但是,我得到的是而且显然仍然有白色边框.我如何摆脱它?
However, what I get is and this obviously still has a white border. How do I get rid of it?
array.shape是:(256,256,1,1,3)
The array.shape is: (256, 256, 1, 1, 3)
推荐答案
看看我的示例,它可能会对您有所帮助:
Look at my example it may help you:
import numpy as np
import matplotlib.pyplot as plt
def save_image(data, filename):
sizes = np.shape(data)
fig = plt.figure()
fig.set_size_inches(1. * sizes[0] / sizes[1], 1, forward = False)
ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_off()
fig.add_axes(ax)
ax.imshow(data)
plt.savefig(filename, dpi = sizes[0], cmap='hot')
plt.close()
data = np.random.randint(0, 100, (256, 256))
save_image(data, '1.png')
这篇关于在python中使用子图和imshow时删除白色边框(Matplotlib)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文