Coverage for tcvx21/plotting/save_figure_m.py: 90%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from pathlib import Path
2import matplotlib.pyplot as plt
4def savefig(fig, output_path: Path=None, facecolor='w', bbox_inches='tight', dpi=300,
5 show = False, close = True):
6 """
7 Save a figure to file
8 """
10 if output_path is not None:
11 output_path.parent.mkdir(parents=True, exist_ok=True)
12 plt.savefig(output_path, facecolor=facecolor, bbox_inches=bbox_inches, dpi=dpi)
14 if show:
15 plt.show()
16 elif close:
17 plt.close(fig)