Created
November 5, 2017 07:41
-
-
Save CMCDragonkai/f074f3ab2f294109771be1881f4d7db0 to your computer and use it in GitHub Desktop.
Bracketing Pattern (Context Manager) for Matplotlib Figures #python #matplotlib
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 contextlib | |
import matplotlib.pyplot as plt | |
@contextlib.contextmanager | |
def figure(*args, **kwargs): | |
fig = plt.figure(*args, **kwargs) | |
yield fig | |
plt.close(fig) | |
# use it like `with figure() as fig:` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment