plt.savefig存储图片消除白边

# 读取图片
plt.imshow(data[15][0])


plt.axis("off")
# 去除图像周围的白边 
height, width, channels = img.shape 
# 如果dpi=300,那么图像大小=height*width 
fig.set_size_inches(width/100.0/3.0, height/100.0/3.0) 
plt.gca().xaxis.set_major_locator(plt.NullLocator()) 
plt.gca().yaxis.set_major_locator(plt.NullLocator()) 
plt.subplots_adjust(top=1,bottom=0,left=0,right=1,hspace=0,wspace=0) 
plt.margins(0,0)
plt.savefig("./imgs/xxx.png", bbox_inches="tight", pad_inches=0.0)

其中 bbox_inches = 'tight' 可以去除坐标轴占用的空间(如果只是set_visiable = False,只能不显示,但空间还占用)

       dpi指定为原图的dpi,控制保存图片的质量/分辨率

      pad_inches = 0 这句是重点,去除所有白边

 

  • 11
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值