alphapepttools.pl.save_figure#
- alphapepttools.pl.save_figure(fig, filename, output_dir, dpi=None, transparent=False, **kwargs)#
Save a figure in a publication-friendly format
Saves matplotlib figures with appropriate settings for scientific publications, automatically creating the output directory if it doesn’t exist. Uses configured DPI settings by default for consistent high-quality output.
- Parameters:
fig (
Figure) – The figure to savefilename (
str) – The filename to save the figure. Must have a supported extension. If no extension is given, the figure will be saved as a .png fileoutput_dir (
str) – The directory to save the figure in. Will be created if it does not existdpi (
int|None(default:None)) – The resolution of the figure, taken by default from configtransparent (
bool(default:False)) – Whether to save a .png figure with a transparent background**kwargs – Additional keyword arguments to pass to fig.savefig
- Return type:
- Returns:
None
Examples
Save a figure with default settings:
from alphapepttools.pl.figure import create_figure, save_figure import numpy as np fig, axm = create_figure(1, 1) ax = axm.next() ax.plot(np.random.randn(100)) save_figure(fig, "my_plot.png", "figures/")
Save with custom DPI and transparency:
from alphapepttools.pl.figure import create_figure, save_figure fig, axm = create_figure(1, 2, figsize=(8, 4)) # ... create plots ... save_figure(fig, "figure_transparent.pdf", "output/publication/", dpi=600, transparent=True)
Notes
The function automatically creates parent directories if they don’t exist. The default DPI is taken from the global configuration settings to ensure consistent resolution across all saved figures.