Coverage for gwcelery/util/matplotlib.py: 100%

11 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-04-11 16:33 +0000

1"""Matplotlib environment management.""" 

2from contextlib import contextmanager 

3 

4from matplotlib import pyplot as plt 

5 

6__all__ = ('closing_figures',) 

7 

8 

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)