opendvp.io.export_figure#
- export_figure(fig, path_to_dir, suffix, dpi=300)#
Save a matplotlib figure as both PDF and SVG files with a timestamped filename.
The function creates the output directory if it does not exist, generates a timestamped filename using the current date and time, and saves the figure in both PDF and SVG formats with the specified DPI. For SVG export, it ensures that text remains editable in vector graphics editors like Adobe Illustrator.
- Parameters:
fig (matplotlib.figure.Figure) – The matplotlib figure object to be saved.
path_to_dir (str) – Directory path where the figure files will be saved.
suffix (str) – A custom suffix to include in the filename (e.g., describing the content).
dpi (int, optional) – Resolution in dots per inch for the saved figure. Default is 300.
- Return type:
- Returns:
None
Prints
——–
str – Confirmation message with the full paths to the saved PDF and SVG files.
Examples
>>> import matplotlib.pyplot as plt >>> fig, ax = plt.subplots() >>> ax.plot([0, 1], [0, 1]) >>> export_figure(fig, path="figures/", suffix="line_plot")
Figures saved as: figures/20250519_1245_line_plot.pdf figures/20250519_1245_line_plot.svg