Plot functions

The following plot functions are provided by the module ba_plot in the bornagain Python package.

Plot single Datafield

A single Datafield can be plotted with

from bornagain import ba_plot as bp
simulation = ...
result = simulation.simulate()
bp.plot_datafield(result)
bp.plt.show()

This function is used in a majority of our scripting examples, for instance in the following short, basic examples:

Plot transformed values

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())
bp.plot_array(values, result.frame())
bp.plt.show()

The array shape must match the frame: (nx,) for a one-dimensional frame and (ny, nx) for a two-dimensional frame.

Plot several curves

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:

from bornagain import ba_plot as bp

def simulate(p):
    simulation = ... # depends on parameter p
    return simulation.simulate()

P = [...] # list of parameter values
results = [simulate(p) for p in P]
bp.plot_multicurve(results)
bp.plt.show()

Plot several frames

To plot several 2D Datafields in as many frames, use one of

plot2d_to_grid(results, ncol, **plotargs)
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 plot2d_to_grid(results, len(results), **plotargs).

Typical usage is as for plot_multicurve, see code snippet above.

Examples: