Python去白边保存图像

2019-08-19  本文已影响0人  BinJiang

import matplotlib.pyplot as plt

fig = plt.gcf()

plt.axis('off')

plt.gca().xaxis.set_major_locator(plt.NullLocator())

plt.gca().xaxis.set_major_locator(plt.NullLocator())

plt.subplots_adjust(top = 1, bottom = 0, right = 1, left = 0, hspace = 0, wspace = 0)

plt.margins(0,0)

fig.savefig('save_name.png')

注意: 如果不采用subplot_adjust + margins(0,0), 而是在fig.savefig()参数中添加bbox_inches = 'tight', 也可以达到

去除空白的效果,但是,这样会导致对图片输出大小设置失效。

上一篇 下一篇

猜你喜欢

热点阅读