python 使用plt画图,去除图片四周的白边方法
作者:xull88619814 时间:2022-02-07 19:34:41
用matplotlib.pyplot画的图,显示和保存的图片周围都会有白边,可以去掉。为了显示的更清楚,给图片加了红色的框
代码
“`
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
im = im[:, :, (2, 1, 0)]
ax.imshow(im, aspect='equal')
plt.axis(‘off')
# 去除图像周围的白边
height, width, channels = im.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)
#dpi是设置清晰度的,大于300就很清晰了,但是保存下来的图片很大
plt.savefig(‘result.png', dpi=300)
来源:https://blog.csdn.net/xull88619814/article/details/82052894
标签:python,plt,图片,白边
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python中itertools模块zip_longest函数详解
2023-01-02 09:09:35
深入讨论Python函数的参数的默认值所引发的问题的原因
2022-08-03 00:54:31
Python Datetime模块和Calendar模块用法实例分析
2022-08-05 10:23:46
Python中针对函数处理的特殊方法
2023-07-17 19:59:30
如何让shell终端和goland控制台输出彩色的文字
2023-07-13 03:24:56
![](https://img.aspxhome.com/file/2023/9/87629_0s.jpg)
优化MySQL的数据库性能的八种方法
2012-01-05 19:28:53
怎样使MySQL在攻击者面前保持安全
2008-11-17 20:09:00
Python OpenCV中的resize()函数的使用
2022-03-23 23:11:56
![](https://img.aspxhome.com/file/2023/4/93814_0s.png)
Python扫描IP段查看指定端口是否开放的方法
2023-10-14 22:57:17
Python模块/包/库安装的六种方法及区别
2021-11-03 15:53:56
![](https://img.aspxhome.com/file/2023/4/72964_0s.png)
Javascript DOM 编程实例讲解--仿LightBox效果提示框
2008-05-01 13:25:00
![](https://img.aspxhome.com/file/UploadPic/up/2008050116095611.gif)
详解如何利用Python制作24点小游戏
2022-02-04 17:22:42
![](https://img.aspxhome.com/file/2023/2/66882_0s.jpg)
简单介绍一下pyinstaller打包以及安全性的实现
2021-07-23 15:34:56
![](https://img.aspxhome.com/file/2023/8/78718_0s.png)
使用ewebeditor可能会重复提交数据两次的解决办法
2009-01-09 12:41:00
python 接收处理外带的参数方法
2022-05-01 17:56:26
django rest framework 实现用户登录认证详解
2023-05-10 10:19:05
![](https://img.aspxhome.com/file/2023/3/99553_0s.png)
HTML语言将加入硬件操作功能
2009-12-16 19:19:00
![](https://img.aspxhome.com/file/UploadPic/200912/16/01-55s.jpg)
页面重构中的模块化思维
2009-06-28 15:36:00
Python用摘要算法生成token及检验token的示例代码
2022-05-30 10:22:10
基于PyQt5制作一个表情包下载器
2022-02-23 13:30:58
![](https://img.aspxhome.com/file/2023/9/91959_0s.png)