Created
March 9, 2012 21:50
-
-
Save stober/2008909 to your computer and use it in GitHub Desktop.
Pylab Save/Plot Decorator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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