matplotlib - Plt.show shows full graph but savefig is cropping the image (python) -


my code succesfully saving images file, cropping important details right hand side. answers exist fixing problem when arises plt.show, savefig command incorrectly producing graph in example. how can fixed?

the relevant sample of code:

import glob import os 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 images (top plt.show , bottom file produced savefig:

image when shown plt.show image when saved file


you may try

plt.savefig('x:/' + newname + '.png', bbox_inches='tight') 

or may define figure size like

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

Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -