Skip to content

Instantly share code, notes, and snippets.

@stober
Created March 9, 2012 21:50
Show Gist options
  • Save stober/2008909 to your computer and use it in GitHub Desktop.
Save stober/2008909 to your computer and use it in GitHub Desktop.
Pylab Save/Plot Decorator
import matplotlib.pyplot as plt
def save_show_no(plotfunc):
# A function decorator that adds the option to save or show a plot
# depending on whether a filename option is set.
def decorate(*args,**kwargs):
ax = plotfunc(*args)
if 'filename' in kwargs.keys():
plt.savefig(kwargs['filename'])
elif 'show' in kwargs.keys():
plt.show()
else:
return ax
return decorate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment