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画图,去除图片四周的白边方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持中文源码网。