Python plt 移除坐标轴,边框不可见

img = img.resize((input_image.shape[0], input_image.shape[1]), Image.LANCZOS)

img = np.array(img)
plt.imshow(img)
plt.axis('off')
fig = plt.gcf()
fig.set_size_inches(1.0 / 3, 1.0 / 3)  # dpi = 300, output = 100*100 pixels
plt.gca().xaxis.set_major_locator(plt.NullLocator())
plt.gca().yaxis.set_major_locator(plt.NullLocator())
plt.subplots_adjust(top=1, bottom=0, right=1, left=0, hspace=0, wspace=0)
plt.margins(0, 0)
frame = plt.gca()
# y 轴不可见
frame.axes.get_yaxis().set_visible(False)
# x 轴不可见
frame.axes.get_xaxis().set_visible(False)
fig.savefig(layer_name.split('/')[0] +'_'+str(i)+ '.png', transparent=True, dpi=300, pad_inches=0)

 

你可能感兴趣的:(Python)