in src/alpaca_eval/plotting.py [0:0]
def save_fig(fig, filename, dpi=300, is_tight=True):
"""General function for saving many different types of figures."""
# order matters ! and don't use elif!
if isinstance(fig, sns.FacetGrid):
fig = fig.fig
if isinstance(fig, matplotlib.artist.Artist): # any type of axes
fig = fig.get_figure()
if isinstance(fig, matplotlib.figure.Figure):
plt_kwargs = {}
if is_tight:
plt_kwargs["bbox_inches"] = "tight"
fig.savefig(filename, dpi=dpi, **plt_kwargs)
plt.close(fig)
else:
raise ValueError(f"Unknown figure type {type(fig)}")