python 使用plt画图,去除图片四周的白边方法
时间:2021-07-09 08:25:58|栏目:Python代码|点击: 次
用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代码解决RenderView窗口not found问题
栏 目:Python代码
本文标题:python 使用plt画图,去除图片四周的白边方法
本文地址:http://www.codeinn.net/misctech/154654.html






