File: _index.md

package info (click to toggle)
bornagain 23.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 103,948 kB
  • sloc: cpp: 423,131; python: 40,997; javascript: 11,167; awk: 630; sh: 318; ruby: 173; xml: 130; makefile: 51; ansic: 24
file content (63 lines) | stat: -rw-r--r-- 2,036 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
+++
title = "Plotting"
weight = 70
+++

# Plotting with ba_plot

To plot simulation results (possibly along with experimental data),
different methods are viable:
* [Export](/ref/data/datafield/export) simulated data to files,
and plot them with some external tool;
* [Convert](/ref/data/datafield/export) simulated data to NumPy arrays,
and plot them with any Python-based tool;
* Plot simulated data with [MatPlotLib](https://matplotlib.org) under Python,
using utility functions provided by BornAgain.

In the following, we will explain the last of these three methods.

### Overview

MatPlotLib-based plotting functions are provided by Python module `ba_plot`
that is part of the `bornagain` Python package.
It is typically used through
```python
from bornagain import ba_plot as bp
```

It provides the functions
```python
plot_simulation_result(result, **plotargs) # plot one Datafield
plot_multicurve(results, **plotargs)       # several 1d Datafields in one frame
make_plot(results, ncol, **plotargs)       # one Datafield per frame in a grid
make_plot_row(results, **plotargs)         # one Datafield per frame in a row
```

where `result` is a Datafield as returned by `simulation.simulate()`,
and `results` is a list of Datafields.

To finalize a plot, call one of
```python
bp.plt.show()          # launch MatPlotLib window to display the plot
bp.export(**plotargs)  # write the plot to an image file (explained below)
```

### Further reading

See
* [Plot functions](functions), more on the above listed plot functions
* [Heat map](heatmap), change the color scheme for 2D plots
* [LaTeX markup](latex), in labels and legends, `$...$` typeset with LaTeX

See also:
* [Plotting with axes in different units](axes-in-different-units)


### Code location

The functions documented in this section of the online manual
are all implemented in the Python module
[`ba_plot`]({{% url-src %}}/Wrap/Python/src/bornagain/ba_plot.py).

If our plot functions are not versatile enough for your needs,
then copy, rename, and modify them.