Export plot to file

Interactively

To create image files interactively, run a BornAgain script that contains

import bornagain as ba

ba.plt.show()

then click the “diskette” icon in the MatPlotLib window.

Programmatically

To create image files programmatically, replace the Python statement

ba.plt.show()

by one of

ba.export("result.svg")

The filename may also be passed as figfile="result.svg" or obtained through the command-line mechanism described in Configuration. The image format is deduced from the extension of the filename. export saves the current figure; it does nothing when figfile is None or an empty string. Use help(ba.export) for the call signature. To both save and display a plot, call export before ba.plt.show().

Image formats

Which image formats are supported depends on the local MatPlotLib installation. To find out, either click on the export (“diskette”) icon in an interactive MatPlotLib widget, or run the following Python lines:

import bornagain as ba

fig = ba.plt.figure()
print(fig.canvas.get_supported_filetypes())

For plots generated by BornAgain, prefer a vector image format, with extension .svg, .eps, .ps, or .pdf. Maybe .emf is still useful under Windows.