python 使用plt画图,去除图片四周的白边 您所在的位置:网站首页 tecplot输出图片如何去掉空白部分 python 使用plt画图,去除图片四周的白边

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

2024-01-28 08:12| 来源: 网络整理| 查看: 265

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

这里写图片描述



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有