In this tutorial, we demonstrate the plotting tools built-in to `bilby` and how to extend them. First, we run a simple injection study and return the `result` object.
%% Cell type:code id: tags:
``` python
importbilby
importmatplotlib.pypltasplt
importmatplotlib.pyplotasplt
%matplotlibinline
time_duration=4.# time duration (seconds)
sampling_frequency=2048.# sampling frequency (Hz)
outdir='visualising_the_results'# directory in which to store output
label='example'# identifier to apply to output files
injection_parameters=dict(
mass_1=36.,# source frame (non-redshifted) primary mass (solar masses)
mass_2=29.,# source frame (non-redshifted) secondary mass (solar masses)
a_1=0.4,# primary dimensionless spin magnitude
a_2=0.3,# secondary dimensionless spin magnitude
tilt_1=0.5,# polar angle between primary spin and the orbital angular momentum (radians)
tilt_2=1.0,# polar angle between secondary spin and the orbital angular momentum
phi_12=1.7,# azimuthal angle between primary and secondary spin (radians)
phi_jl=0.3,# azimuthal angle between total angular momentum and orbital angular momentum (radians)
luminosity_distance=200.,# luminosity distance to source (Mpc)
iota=0.4,# inclination angle between line of sight and orbital angular momentum (radians)
phase=1.3,# phase (radians)
waveform_approximant='IMRPhenomPv2',# waveform approximant name
reference_frequency=50.,# gravitational waveform reference frequency (Hz)
ra=1.375,# source right ascension (radians)
dec=-1.2108,# source declination (radians)
geocent_time=1126259642.413,# reference time at geocentre (time of coalescence or peak amplitude) (GPS seconds)
In running this code, we already made the first plot! In the function `bilby.detector.get_interferometer_with_fake_noise_and_injection`, the ASD, detector data, and signal are plotted together. This figure is saved under `visualsing_the_results/H1_frequency_domain_data.png`. Note that `visualising_the_result` is our `outdir` where all the output of the run is stored. Let's take a quick look at that directory now:
%% Cell type:code id: tags:
``` python
!lsvisualising_the_results/
```
%% Cell type:markdown id: tags:
## Corner plots
Now lets make some corner plots. You can easily generate a corner plot using `result.plot_corner()` like this:
%% Cell type:code id: tags:
``` python
result.plot_corner()
plt.show()
```
%% Cell type:markdown id: tags:
In a notebook, this figure will display. But by default the file is also saved to `visualising_the_result/example_corner.png`. If you change the label to something more descriptive then the `example` here will of course be replaced.
%% Cell type:markdown id: tags:
You may also want to plot a subset of the parameters, or perhaps add the `injection_paramters` as lines to check if you recovered them correctly. All this can be done through `plot_corner`. Under the hood, `plot_corner` uses
[chain consumer](https://samreay.github.io/ChainConsumer/index.html), and all the keyword arguments passed to `plot_corner` are passed through to [the `plot` function of chain consumer](https://samreay.github.io/ChainConsumer/chain_api.html#chainconsumer.plotter.Plotter.plot).
### Adding injection parameters to the plot
In the previous plot, you'll notice `bilby` added the injection parameters to the plot by default. You can switch this off by setting `truth=None` when you call `plot_corner`. Or to add different injection parameters to the plot, just pass this as a keyword argument for `truth`. In this example, we just add a line for the luminosity distance by passing a dictionary of the value we want to display.
Notice here, we also passed in a keyword argument `filename=`, this overwrites the default filename and instead saves the file as `visualising_the_results/subset.png`. Useful if you want to create lots of different plots. Let's check what the outdir looks like now
%% Cell type:code id: tags:
``` python
!lsvisualising_the_results/
```
%% Cell type:markdown id: tags:
## Alternative
If you would prefer to do the plotting yourself, you can get hold of the samples and the ordering as follows and then plot with a different module. Here is an example using the [`corner`](http://corner.readthedocs.io/en/latest/) package
%% Cell type:code id: tags:
``` python
importcorner
samples=result.samples
labels=result.parameter_labels
fig=corner.corner(samples,labels=labels)
plt.show()
```
%% Cell type:markdown id: tags:
## Other plots
We also include some other types of plots which may be useful. Again, these are built on chain consumer so you may find it useful to check the [documentation](https://samreay.github.io/ChainConsumer/chain_api.html#plotter-class) to see how these plots can be extended. Below, we show just one example of these.
#### Distribution plots
These plots just show the 1D histograms for each parameter