Coverage for gwcelery/util/matplotlib.py: 100%
11 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-11-14 05:52 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2024-11-14 05:52 +0000
1"""Matplotlib environment management."""
2from contextlib import contextmanager
4from matplotlib import pyplot as plt
6__all__ = ('closing_figures',)
9@contextmanager
10def closing_figures():
11 """Close figure that are created in a with: statement."""
12 old_fignums = set(plt.get_fignums())
13 try:
14 yield
15 finally:
16 new_fignums = set(plt.get_fignums())
17 for fignum in new_fignums - old_fignums:
18 plt.close(fignum)