.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_auto_examples/save_current_figure.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr__auto_examples_save_current_figure.py: Save Current Figure ===================================== :func:`sysplot.save_current_figure` saves the active Matplotlib figure to a file next to the calling script. It uses a structured naming convention ``Bild_{chapter}_{number}_{script}{_suffix}.{fmt}`` and creates the output directory ``{folder}/{language}/`` automatically. The file format, output folder, and transparency all default to values in :class:`sysplot.SysplotConfig`. .. GENERATED FROM PYTHON SOURCE LINES 10-57 .. rst-class:: sphx-glr-horizontal * .. image-sg:: /_auto_examples/images/sphx_glr_save_current_figure_001.png :alt: Default (pdf) :srcset: /_auto_examples/images/sphx_glr_save_current_figure_001.png :class: sphx-glr-multi-img * .. image-sg:: /_auto_examples/images/sphx_glr_save_current_figure_002.png :alt: PNG format :srcset: /_auto_examples/images/sphx_glr_save_current_figure_002.png :class: sphx-glr-multi-img * .. image-sg:: /_auto_examples/images/sphx_glr_save_current_figure_003.png :alt: Transparent background :srcset: /_auto_examples/images/sphx_glr_save_current_figure_003.png :class: sphx-glr-multi-img * .. image-sg:: /_auto_examples/images/sphx_glr_save_current_figure_004.png :alt: Custom folder :srcset: /_auto_examples/images/sphx_glr_save_current_figure_004.png :class: sphx-glr-multi-img * .. image-sg:: /_auto_examples/images/sphx_glr_save_current_figure_005.png :alt: German variant with suffix :srcset: /_auto_examples/images/sphx_glr_save_current_figure_005.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none Default: /home/runner/work/sysplot/sysplot/docs/examples/images/en/Bild_1_1_save_current_figure.pdf PNG: /home/runner/work/sysplot/sysplot/docs/examples/images/en/Bild_1_2_save_current_figure.png Transparent: /home/runner/work/sysplot/sysplot/docs/examples/images/en/Bild_1_3_save_current_figure.pdf Custom folder: /home/runner/work/sysplot/sysplot/docs/examples/figures/en/Bild_1_4_save_current_figure.pdf Suffix: /home/runner/work/sysplot/sysplot/docs/examples/images/de/Bild_2_1_save_current_figure_v2.pdf | .. code-block:: Python import matplotlib.pyplot as plt import numpy as np import sysplot as ssp ssp.apply_config() x = np.linspace(0, 2 * np.pi, 200) def make_fig(title): fig, ax = plt.subplots(figsize=ssp.get_figsize()) ax.plot(x, np.sin(x)) ax.set(title=title, xlabel="x", ylabel="y") # Default: fmt and folder from SysplotConfig # → images/en/Bild_1_1_save_current_figure.pdf make_fig("Default (pdf)") path = ssp.save_current_figure(chapter=1, number=1, language="en") print(f"Default: {path}") # Custom format: save as PNG # → images/en/Bild_1_2_save_current_figure.png make_fig("PNG format") path = ssp.save_current_figure(chapter=1, number=2, language="en", fmt="png") print(f"PNG: {path}") # Transparent background (useful for slides/reports) # → images/en/Bild_1_3_save_current_figure.pdf make_fig("Transparent background") path = ssp.save_current_figure(chapter=1, number=3, language="en", transparent=True) print(f"Transparent: {path}") # Custom output folder # → figures/en/Bild_1_4_save_current_figure.pdf make_fig("Custom folder") path = ssp.save_current_figure(chapter=1, number=4, language="en", folder="figures") print(f"Custom folder: {path}") # Suffix to distinguish variants of the same figure number # → images/de/Bild_2_1_save_current_figure_v2.pdf make_fig("German variant with suffix") path = ssp.save_current_figure(chapter=2, number=1, language="de", suffix="v2") print(f"Suffix: {path}") plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.713 seconds) .. _sphx_glr_download__auto_examples_save_current_figure.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: save_current_figure.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: save_current_figure.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: save_current_figure.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_