The following plot functions are available directly from the bornagain
Python package.
A single Datafield can be plotted with
import bornagain as ba
simulation = ...
result = simulation.simulate()
ba.plot_datafield(result)
ba.plt.show()
This function is used in a majority of our scripting examples, for instance in the following short, basic examples:
To plot a NumPy array obtained by transforming a simulation result, use the result’s frame to preserve the physical axes:
values = transform(result.intensities())
ba.plot_array(values, result.frame())
ba.plt.show()
The array shape must match the frame: (nx,) for a one-dimensional frame and
(ny, nx) for a two-dimensional frame.
To draw one or several specular channels, each as a simulated line plus experimental points with error bars, use
ba.plot_specular_curves([(label, measured, simulated), ...], ax=None,
yscale='log', ylim=None)
where measured and simulated are 1D Datafields (one may be None);
measured uncertainties are taken from the Datafield errors. Extra
keyword arguments style the simulated lines; color applies to all
entries of the call. After adding all curves, the caller can create a
legend with ax.legend(). See the
spin-asymmetry examples.
To draw one or more material SLD profiles on a shared subplot, use
ba.plot_material_profile(
[(label, z, sld), ...], z_unit=nm, ax=ax, xlabel="z (nm)")
The explicit z_unit converts BornAgain’s internal length values to the unit
shown on the horizontal axis. Complex SLD values are plotted by their real
part. The caller can add a legend with ax.legend(). See the
honeycomb fit example.
Specular simulations yield one-dimensional Datafields that are plotted as curves y(x). Several such curves can be plotted in one frame. This is often used to demonstrate the effect of varying one parameter. See e.g. the examples
Typical usage:
import bornagain as ba
def simulate(p):
simulation = ... # depends on parameter p
return simulation.simulate()
P = [...] # list of parameter values
results = [simulate(p) for p in P]
ba.plot_multicurve(results)
ba.plt.show()
To plot several 2D Datafields in as many frames, use one of
ba.plot2d_to_grid(results, ncol, **plotargs)
ba.plot2d_to_row(results, **plotargs)
The first of these creates a grid with ncol frames per row.
The second puts all frames in a single row;
it is equivalent to ba.plot2d_to_grid(results, len(results), **plotargs).
Typical usage is as for plot_multicurve, see code snippet above.
Examples: