Use these helpers through import bornagain as ba. The descriptions below
focus on what each function is for; help(ba.plot_datafield), for example,
shows its arguments and defaults.
For a compact function list, see the
plotting overview.
plot_datafield is the general entry point for one simulation result.
It selects plot_curve for 1D data and plot_heatmap for 2D data, using
their defaults. A 2D field with just one row or column is drawn as a curve.
result = simulation.simulate()
ba.plot_datafield(result)
ba.plt.show()
Use the dimension-specific functions below when you need curve options or access to the heat-map image.
plot_array draws a NumPy array using a BornAgain frame for its physical
axes. Use it after transforming a result’s intensities:
values = transform(result.intensities())
ba.plot_array(values, result.frame())
The array must match the frame: (nx,) in 1D or (ny, nx) in 2D.
See Reflectivity Q4.
plot_curve draws any 1D Datafield: reflectivity, a detector slice, or
transformed data. It returns the subplot. Measurements are optional and
appear as points with error bars when the measured Datafield provides errors:
ax = ba.plot_curve(simulated, measured=experimental, label="Sample")
Without measured, only the simulated line is drawn. label names the
curve in the legend; otherwise the Datafield title is used. title sets
the subplot title. The vertical scale is logarithmic by default; use
yscale='linear' for signed data.
This function also works as a fit-monitoring panel.
plot_multicurve compares several 1D results on one subplot. It can also
pair each result with measurements:
fig, ax = ba.plt.subplots()
ba.plot_multicurve(
[simulated_pp, simulated_mm],
measured=[measured_pp, measured_mm],
labels=["++", "--"],
ax=ax,
)
ax.legend()
ba.plt.show()
The two sequences pair by position and must have equal lengths. Each pair
shares a color and legend entry; measured and simulated sampling grids may
differ. A None entry omits one half of a pair, allowing measured-only
curves too. Without measured, all results are drawn as lines.
For both curve functions, lineargs and pointargs control line and
measured-point styles. When you pass ax, you manage the legend; otherwise
the helper creates it from the curve labels. See
Configuration for shared styling and scale choices.
Examples: magnetic reflectivity and spin asymmetry.
plot_heatmap draws a 2D Datafield and returns the MatPlotLib image.
Use it directly to compose image plots or add a mask overlay:
image = ba.plot_heatmap(result)
ba.plot_mask_overlay(mask, image)
plot_mask_overlay covers pixels marked True in a matching boolean
mask. It reuses the image’s position and orientation and leaves the data
unchanged. See Heat map for color scales and overlays.
plot2d_to_row and plot2d_to_grid create a figure of 2D Datafields with
one shared color scale and colorbar. This makes intensities comparable
across panels:
ba.plot2d_to_grid(results, ncol=3)
Use plot2d_to_row(results) for a single row. Datafield titles label the
panels.
plot_ff_to_row presents form-factor images in one row with the colorbar
label |F(q)|²/V² and an upper color limit of 1 by default. It expects
already normalized values; it does not rescale the input data.
Examples: grid, row, and form factors.
plot_material_profile draws one or more real SLD profiles. Each input
entry contains a label, depth coordinates, and SLD values:
z, sld = ba.materialProfile(sample, 400)
ax = ba.plot_material_profile(
[("Model", z, sld)], z_unit=ba.nm, xlabel="z (nm)")
ax.legend()
z_unit converts the coordinates to the displayed unit. Complex SLD
values are drawn by their real part. See
Material profiles for calculating these arrays and
the honeycomb fit example.