Plotting with BornAgain

BornAgain provides MatPlotLib-based helpers for plotting simulation results, measurements, and derived data. They are available directly from the Python package through import bornagain as ba.

This reference explains which helper to choose and how to combine them. Every plotting function has a docstring: use help(ba.plot_curve), for example, for its signature, parameter descriptions, and defaults.

At a glance

Function Use
plot_datafield One Datafield, as a curve or heat map.
plot_array An array with physical axes from a frame.
plot_curve One 1D curve, optionally with measurements.
plot_multicurve Several 1D curves with optional measurements.
plot_heatmap One 2D image.
plot_mask_overlay Mark excluded pixels on an existing image.
plot2d_to_row Images in one row, with a shared color scale.
plot2d_to_grid Images in a grid, with a shared color scale.
plot_ff_to_row Form-factor images with a shared color scale.
plot_material_profile One or more real SLD profiles.
export Save the current figure to an image file.
parse_commandline Read a script’s key=value options.

For live fit progress, see Fit monitoring. For the sample geometry rather than its scattering result, use showSample3D.

First plot

import bornagain as ba

ba.plot_datafield(result)
ba.plt.show()

In a standalone script, call ba.plt.show() once after preparing all plots to display the open figures, not after each plotting function. Short snippets below may omit it. When only saving files, no show() is needed; Jupyter notebooks normally display figures automatically.

Compose and save

ba.plt is MatPlotLib’s pyplot module. To put a BornAgain plot into your own figure, create a subplot and pass it through ax:

fig, ax = ba.plt.subplots()
ba.plot_datafield(result, ax=ax)
ax.grid(True)
ba.export("result.svg")

For a heat map on a supplied subplot, request its colorbar with with_cb=True. For several curve calls on one subplot, finish with ax.legend().

You can also export data or convert them to NumPy arrays and use another plotting tool.