Plt.show显示完整图形,但savefig裁剪图像 [英] Plt.show shows full graph but savefig is cropping the image

查看:44
本文介绍了Plt.show显示完整图形,但savefig裁剪图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码成功地将图像保存到文件中,但它正在从右侧裁剪重要的细节.一起显示时的图像

<小时>

解决方案

您可以尝试

plt.savefig('X:/' + newName + '.png', bbox_inches='tight')

或者你可以像这样定义图形大小

fig = plt.figure(figsize=(9, 11))...plt.savefig(文件名,bbox_inches ='tight')

My code is succesfully saving images to file, but it is cropping important details from the right hand side. Answers exist for fixing this problem when it arises for plt.show, but it is the savefig command that is incorrectly producing the graph in this example. How can this be fixed?

The relevant sample of my code:

import glob
import os
for file in glob.glob("*.oax"):
    try:
        spc_file = open(file, 'r').read()
        newName = file[6:8] + '-' + file[4:6] + '-' + file[0:4] + ' ' + file[8:12] +  ' UTC (Observed) - No Sea Breeze Day'
        plt.title(newName, fontsize=12, loc='left')
        plt.savefig('X:/' + newName + '.png')        
        plt.show()
    except Exception:
        pass

And the images (top is plt.show and bottom is file produced from savefig:


解决方案

You may try

plt.savefig('X:/' + newName + '.png', bbox_inches='tight')

Or you may define figure size like

fig = plt.figure(figsize=(9, 11))
...
plt.savefig(filename, bbox_inches = 'tight')

这篇关于Plt.show显示完整图形,但savefig裁剪图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆