Created
June 21, 2023 17:27
-
-
Save cwindolf/75a03aa466726f8149ddcd065a51a923 to your computer and use it in GitHub Desktop.
Matplotlib context manager helpers
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 | |
import contextlib | |
@contextlib.contextmanager | |
def subplots(*args, **kwargs): | |
fig, axes = plt.subplots(*args, **kwargs) | |
try: | |
yield fig, axes | |
finally: | |
plt.show() | |
plt.close(fig) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment