import os
import matplotlib.pyplot as plt

def savefig(filename,path="figs",fig=None,ext='eps',**kwargs):
	# try:
	#         os.remove(path)
	# except OSError as e:
	#         try:
	#                 os.mkdir(path)
	#         except:
	#                 pass
	if not os.path.exists(path):
		os.makedirs(path)

	filename       = ''.join([path,'/',filename])
	final_filename = '{}.{}'.format(filename,ext).replace(" ","").replace("\n","")

	if fig != None:
		fig.savefig(final_filename,**kwargs)
	else:
		plt.savefig(final_filename,**kwargs)

import os
import matplotlib.pyplot as plt

def savefig(filename,path="figs",fig=None,ext='eps',**kwargs):
	# try:
	#         os.remove(path)
	# except OSError as e:
	#         try:
	#                 os.mkdir(path)
	#         except:
	#                 pass
	if not os.path.exists(path):
		os.makedirs(path)

	filename       = ''.join([path,'/',filename])
	final_filename = '{}.{}'.format(filename,ext).replace(" ","").replace("\n","")

	if fig != None:
		fig.savefig(final_filename,bbox_inches='tight',**kwargs)
	else:
		plt.savefig(final_filename,bbox_inches='tight',**kwargs)

Save figures with white space cropped out
Save figures with white space cropped out

  import os
  import matplotlib.pyplot as plt
  
  def savefig(filename,path="figs",fig=None,ext='eps',**kwargs):
  	# try:
  	#         os.remove(path)
  	# except OSError as e:
  	#         try:
  	#                 os.mkdir(path)
  	#         except:
  	#                 pass
  	if not os.path.exists(path):
  		os.makedirs(path)
  
  	filename       = ''.join([path,'/',filename])
  	final_filename = '{}.{}'.format(filename,ext).replace(" ","").replace("\n","")
  
  	if fig != None:
- 		fig.savefig(final_filename,**kwargs)
+ 		fig.savefig(final_filename,bbox_inches='tight',**kwargs)
  	else:
- 		plt.savefig(final_filename,**kwargs)
+ 		plt.savefig(final_filename,bbox_inches='tight',**kwargs)
  
Save figures with white space cropped out
## Code Before:
import os
import matplotlib.pyplot as plt

def savefig(filename,path="figs",fig=None,ext='eps',**kwargs):
	# try:
	#         os.remove(path)
	# except OSError as e:
	#         try:
	#                 os.mkdir(path)
	#         except:
	#                 pass
	if not os.path.exists(path):
		os.makedirs(path)

	filename       = ''.join([path,'/',filename])
	final_filename = '{}.{}'.format(filename,ext).replace(" ","").replace("\n","")

	if fig != None:
		fig.savefig(final_filename,**kwargs)
	else:
		plt.savefig(final_filename,**kwargs)

## Instruction:
Save figures with white space cropped out
## Code After:
import os
import matplotlib.pyplot as plt

def savefig(filename,path="figs",fig=None,ext='eps',**kwargs):
	# try:
	#         os.remove(path)
	# except OSError as e:
	#         try:
	#                 os.mkdir(path)
	#         except:
	#                 pass
	if not os.path.exists(path):
		os.makedirs(path)

	filename       = ''.join([path,'/',filename])
	final_filename = '{}.{}'.format(filename,ext).replace(" ","").replace("\n","")

	if fig != None:
		fig.savefig(final_filename,bbox_inches='tight',**kwargs)
	else:
		plt.savefig(final_filename,bbox_inches='tight',**kwargs)
