曹子晗

个人博客

欢迎来到我的个人博客


去除matplotlib画图旁边的留白

目录

需要加上

plt.tight_layout(pad=0)

下面给出样例

# x: np.array, shape [H, W, C]
fig, ax = plt.subplots(figsize=(x.shape[1]/100, y.shape[0]/100), dpi=500)
ax.imshow(x)
ax.set_axis_off()  # for image data, if you do not need axis
plt.tight_layout(pad=0)  # remove padding

fig.savefig('/place/you/want/to/save.png/', bbox_inches='tight', pad_inches=0)