网络编程
位置:首页>> 网络编程>> Python编程>> python 使用plt画图,去除图片四周的白边方法

python 使用plt画图,去除图片四周的白边方法

作者:xull88619814  发布时间:2022-02-07 19:34:41 

标签:python,plt,图片,白边

用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)

python 使用plt画图,去除图片四周的白边方法

来源:https://blog.csdn.net/xull88619814/article/details/82052894

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com