Skip to content

Instantly share code, notes, and snippets.

@CMCDragonkai
Created November 5, 2017 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CMCDragonkai/f074f3ab2f294109771be1881f4d7db0 to your computer and use it in GitHub Desktop.
Save CMCDragonkai/f074f3ab2f294109771be1881f4d7db0 to your computer and use it in GitHub Desktop.
Bracketing Pattern (Context Manager) for Matplotlib Figures #python #matplotlib
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