Plotting#
Plotting functionality for RAT results objects is available through the RATapi.utils.plotting
module.
Plots using the matplotlib library
- class RATapi.utils.plotting.LivePlot(block=False)#
Creates a plot that gets updates from the plot event during a calculation
- Parameters:
block (bool, default: False) – Indicates the plot should block until it is closed
- plotEvent(event)#
Callback for the plot event.
- Parameters:
event (PlotEventData) – The plot event data.
- RATapi.utils.plotting.plot_chain(results, params=None, maxpoints=15000, block=False, return_fig=False)#
Plot the MCMC chain for each parameter of a Bayesian analysis.
- Parameters:
results (RATapi.outputs.BayesResults) – The results of a Bayesian analysis.
params (list[int], default None) – The indices or names of a subset of parameters if required. If None, uses all indices.
maxpoints (int) – The maximum number of points to plot for each parameter.
block (bool, default False) – Whether Python should block until the plot is closed.
return_fig (bool, default False) – If True, return the figure as an object instead of showing it.
- Returns:
If return_fig is True, return the figure - otherwise, return nothing.
- Return type:
Figure or None
- RATapi.utils.plotting.plot_contour(results, x_param, y_param, smooth=True, sigma=None, axes=None, block=False, return_fig=False, **hist2d_settings)#
Plot a 2D histogram of two indexed chain parameters, with contours.
- Parameters:
results (RATapi.outputs.BayesResults) – The results of a Bayesian analysis.
x_param (int) – The index or name of the parameter on the x-axis.
y_param (int) – The index or name ofthe parameter on the y-axis.
smooth (bool, default True) – If True, apply Gaussian smoothing to the histogram.
sigma (tuple[float] or None, default None) – If given, is used as parameters for Gaussian smoothing in x and y direction respectively. If None, defaults to the standard deviation of the parameter chain in either direction.
axes (Axes or None, default None) – If provided, plot on the given Axes object.
block (bool, default False) – Whether Python should block until the plot is closed.
return_fig (bool, default False) – If True, return the figure as an object instead of showing it.
**hist2d_settings – Settings passed to np.histogram2d. Default settings are bins = 25 and density = True.
- Returns:
If return_fig is True, return the figure - otherwise, return nothing.
- Return type:
Figure or None
- RATapi.utils.plotting.plot_corner(results, params=None, smooth=True, block=False, return_fig=False, hist_kwargs=None, hist2d_kwargs=None)#
Create a corner plot from a Bayesian analysis.
- Parameters:
results (BayesResults) – The results from a Bayesian calculation.
params (list[int or str], default None) – The indices or names of a subset of parameters if required. If None, uses all indices.
smooth (bool, default True) – Whether to apply Gaussian smoothing to the corner plot.
block (bool, default False) – Whether Python should block until the plot is closed.
return_fig (bool, default False) – If True, return the figure as an object instead of showing it.
hist_kwargs (dict) – Extra keyword arguments to pass to the 1d histograms. Default is {‘density’: True, ‘bins’: 25}
hist2d_kwargs (dict) – Extra keyword arguments to pass to the 2d histograms. Default is {‘density’: True, ‘bins’: 25}
- Returns:
If return_fig is True, return the figure - otherwise, return nothing.
- Return type:
Figure or None
- RATapi.utils.plotting.plot_hists(results, params=None, smooth=True, sigma=None, estimated_density=None, block=False, return_fig=False, **hist_settings)#
Plot marginalised posteriors for several parameters from a Bayesian analysis.
- Parameters:
results (BayesResults) – The results from a Bayesian calculation.
params (list[int], default None) – The indices or names of a subset of parameters if required. If None, uses all indices.
smooth (bool, default True) – Whether to apply a Gaussian smoothing to the histogram. Defaults to True.
sigma (float or None, default None) – If given, is used as the sigma-parameter for the Gaussian smoothing. If None, the default (1/3rd of parameter chain standard deviation) is used.
estimated_density (dict, default None) – If None (default), ignore. Can also be a string ‘normal’, ‘lognor’ or ‘kernel’ to apply the same estimated density to all parameters. Else, a dictionary where the keys are indices or names of parameters, and values denote an estimated density of the given form on top of the histogram: None : do not plot estimated density for this parameter. ‘normal’: normal Gaussian. ‘lognor’: Log-normal probability density. ‘kernel’: kernel density estimation. To provide a default estimated density function to all parameters that haven’t been specifically set, pass the ‘default’ key, e.g. to apply ‘normal’ to all unset parameters, set estimated_density = {‘default’: ‘normal’}.
block (bool, default False) – Whether Python should block until the plot is closed.
return_fig (bool, default False) – If True, return the figure as an object instead of showing it.
hist_settings – Settings passed to np.histogram. By default, the settings passed are bins = 25 and density = True.
- Returns:
If return_fig is True, return the figure - otherwise, return nothing.
- Return type:
Figure or None
- RATapi.utils.plotting.plot_one_hist(results, param, smooth=True, sigma=None, estimated_density=None, axes=None, block=False, return_fig=False, **hist_settings)#
Plot the marginalised posterior for a parameter of a Bayesian analysis.
- Parameters:
results (BayesResults) – The results from a Bayesian calculation.
param (Union[int, str]) – Either the index or name of a parameter.
block (bool, default False) – Whether Python should block until the plot is closed.
smooth (bool, default True) – Whether to apply Gaussian smoothing to the histogram. Defaults to True.
sigma (float or None, default None) – If given, is used as the sigma-parameter for the Gaussian smoothing. If None, the default (1/3rd of parameter chain standard deviation) is used.
estimated_density ('normal', 'lognor', 'kernel' or None, default None) – If None (default), ignore. Else, add an estimated density of the given form on top of the histogram by the following estimations: ‘normal’: normal Gaussian. ‘lognor’: Log-normal probability density. ‘kernel’: kernel density estimation.
axes (Axes or None, default None) – If provided, plot on the given Axes object.
block – Whether Python should block until the plot is closed.
return_fig (bool, default False) – If True, return the figure as an object instead of showing it.
**hist_settings – Settings passed to np.histogram. By default, the settings passed are bins = 25 and density = True.
- Returns:
If return_fig is True, return the figure - otherwise, return nothing.
- Return type:
Figure or None
- RATapi.utils.plotting.plot_ref_sld(project, results, block=False, return_fig=False, bayes=None, linear_x=False, q4=False, show_error_bar=True, show_grid=False, show_legend=True)#
Plots the reflectivity and SLD profiles.
- Parameters:
project (Project) – An instance of the Project class
results (Union[Results, BayesResults]) – The result from the calculation
block (bool, default: False) – Indicates the plot should block until it is closed
return_fig (bool, default False) – If True, return the figure instead of displaying it.
bayes (65, 95 or None, default None) – Whether to shade Bayesian confidence intervals. Can be None (if no intervals), 65 to show 65% confidence intervals, and 95 to show 95% confidence intervals.
linear_x (bool, default: False) – Controls whether the x-axis on reflectivity plot uses the linear scale
q4 (bool, default: False) – Controls whether Q^4 is plotted on the reflectivity plot
show_error_bar (bool, default: True) – Controls whether the error bars are shown
show_grid (bool, default: False) – Controls whether the grid is shown
show_legend (bool, default: True) – Controls whether the legend is shown
- Returns:
Returns Figure if return_fig is True, else returns nothing.
- Return type:
Figure or None