save_svg_as_emf

pyhelpers.store.save_svg_as_emf(path_to_svg, path_to_emf, verbose=False, inkscape_exe=None, **kwargs)[source]

Save a SVG file (.svg) as a EMF file (.emf).

Parameters:
  • path_to_svg (str) – Path where a .svg file is saved.

  • path_to_emf (str) – Path where a .emf file is saved.

  • verbose (bool | int) – Whether to print relevant information in console; defaults to False.

  • inkscape_exe (str | None) – An absolute path to ‘inkscape.exe’; defaults to None; when inkscape_exe=None, use the default installation path, e.g. (on Windows) “C:\Program Files\Inkscape\bin\inkscape.exe” or “C:\Program Files\Inkscape\inkscape.exe”.

  • kwargs – [Optional] parameters of subprocess.run.

Examples:

>>> from pyhelpers.store import save_svg_as_emf
>>> from pyhelpers.dirs import cd
>>> from pyhelpers.settings import mpl_preferences
>>> import matplotlib.pyplot as plt

>>> mpl_preferences()

>>> x, y = (1, 1), (2, 2)

>>> plt.figure()
>>> plt.plot([x[0], y[0]], [x[1], y[1]])
>>> plt.show()

The above exmaple is illustrated in Fig. 7:

../_images/store-save_fig-demo.svg

Fig. 7 An example figure created for the function save_svg_as_emf().

>>> img_dir = cd("tests\images")

>>> svg_file_pathname = cd(img_dir, "store-save_fig-demo.svg")
>>> plt.savefig(svg_file_pathname)  # Save the figure as a .svg file

>>> emf_file_pathname = cd(img_dir, "store-save_fig-demo.emf")
>>> save_svg_as_emf(svg_file_pathname, emf_file_pathname, verbose=True)
Saving the .svg file as "tests\images\store-save_fig-demo.emf" ... Done.

>>> plt.close()