figaro.plot module¶
- class figaro.plot.PPPlot(*args, **kwargs)[source]¶
Bases:
Axes
Construct a probability-probability (P-P) plot.
Derived from https://lscsoft.docs.ligo.org/ligo.skymap/_modules/ligo/skymap/plot/pp.html#PPPlot This class avoids installing the whole ligo.skymap.plot package.
- add_confidence_band(nsamples, cl=0.9, **kwargs)[source]¶
Add a target confidence band.
- Parameters:
nsamples (int) – Number of P-values
cl (float, default: 0.9) – Confidence level
**kwargs – optional extra arguments to matplotlib.axes.Axes.fill_betweenx
- add_diagonal(*args, **kwargs)[source]¶
Add a diagonal line to the plot, running from (0, 0) to (1, 1).
- Parameters:
kwargs – optional extra arguments to matplotlib.axes.Axes.plot
- name = 'pp_plot'¶
- set(*, adjustable=<UNSET>, agg_filter=<UNSET>, alpha=<UNSET>, anchor=<UNSET>, animated=<UNSET>, aspect=<UNSET>, autoscale_on=<UNSET>, autoscalex_on=<UNSET>, autoscaley_on=<UNSET>, axes_locator=<UNSET>, axisbelow=<UNSET>, box_aspect=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, facecolor=<UNSET>, forward_navigation_events=<UNSET>, frame_on=<UNSET>, gid=<UNSET>, in_layout=<UNSET>, label=<UNSET>, mouseover=<UNSET>, navigate=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, position=<UNSET>, prop_cycle=<UNSET>, rasterization_zorder=<UNSET>, rasterized=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, subplotspec=<UNSET>, title=<UNSET>, transform=<UNSET>, url=<UNSET>, visible=<UNSET>, xbound=<UNSET>, xlabel=<UNSET>, xlim=<UNSET>, xmargin=<UNSET>, xscale=<UNSET>, xticklabels=<UNSET>, xticks=<UNSET>, ybound=<UNSET>, ylabel=<UNSET>, ylim=<UNSET>, ymargin=<UNSET>, yscale=<UNSET>, yticklabels=<UNSET>, yticks=<UNSET>, zorder=<UNSET>)¶
Set multiple properties at once.
Supported properties are
- Properties:
adjustable: {‘box’, ‘datalim’} agg_filter: a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array and two offsets from the bottom left corner of the image alpha: scalar or None anchor: (float, float) or {‘C’, ‘SW’, ‘S’, ‘SE’, ‘E’, ‘NE’, …} animated: bool aspect: {‘auto’, ‘equal’} or float autoscale_on: bool autoscalex_on: unknown autoscaley_on: unknown axes_locator: Callable[[Axes, Renderer], Bbox] axisbelow: bool or ‘line’ box_aspect: float or None clip_box: ~matplotlib.transforms.BboxBase or None clip_on: bool clip_path: Patch or (Path, Transform) or None facecolor or fc: :mpltype:`color` figure: ~matplotlib.figure.Figure forward_navigation_events: bool or “auto” frame_on: bool gid: str in_layout: bool label: object mouseover: bool navigate: bool navigate_mode: unknown path_effects: list of .AbstractPathEffect picker: None or bool or float or callable position: [left, bottom, width, height] or ~matplotlib.transforms.Bbox prop_cycle: ~cycler.Cycler rasterization_zorder: float or None rasterized: bool sketch_params: (scale: float, length: float, randomness: float) snap: bool or None subplotspec: unknown title: str transform: ~matplotlib.transforms.Transform url: str visible: bool xbound: (lower: float, upper: float) xlabel: str xlim: (left: float, right: float) xmargin: float greater than -0.5 xscale: unknown xticklabels: unknown xticks: unknown ybound: (lower: float, upper: float) ylabel: str ylim: (bottom: float, top: float) ymargin: float greater than -0.5 yscale: unknown yticklabels: unknown yticks: unknown zorder: float
- figaro.plot.joyplot(draws, x_values, y_values, credible_regions=False, fill=True, solid=False, overlap=1.0, xlabel=None, ylabel=None, xunit=None, yunit=None, colormap='coolwarm', out_folder='.', name='joyplot', subfolder=False, show=False, save=True, joy=False)[source]¶
Make a joyplot (also known as ridgeline plot) of a set of distributions. Heavily inspired by leotac’s JoyPy (https://github.com/leotac/joypy).
- Parameters:
draws (np.ndarray) – (n_y, n_x) or (n_y, n_draws, n_x) array containing the distributions to plot
x_values (np.ndarray) – x values at which the distributions are evaluated
y_values (np.ndarray) – y values corresponding to the different distributions
credible_regions (bool) – whether to plot credible regions or not
fill (bool) – whether to fill the space below the distribution or not (ignored if credible_regions is True)
solid (bool) – wheter to fill with transparent or solid colour
overlap (float) – space between different plots
xlabel (str) – x axis label (LaTeX style)
ylabel (str) – colorbar label (LaTeX style)
xunit (str) – x axis units (LaTeX style) - default: no units
yunit (str) – colorbar units (LaTeX style) - default: no units
colormap (str) – a valid matplotlib colormap name
out_folder (str or Path) – output folder
name (str) – name to be given to outputs
subfolder (bool) – whether to save the plots in different subfolders (for multiple events)
save (bool) – whether to save the plots or not
show (bool) – whether to show the plots during the run or not
joy (bool) – format the plot to look like the cover of Joy Division’s “Unknown Pleasures”
- Returns:
figure with the plot
- Return type:
matplotlib.figure.Figure
- figaro.plot.plot_1d_dist(x, draws, injected=None, samples=None, out_folder='.', name='density', label=None, unit=None, show=False, save=True, subfolder=False, true_value=None, true_value_label='\\mathrm{True\\ value}', injected_label='\\mathrm{Simulated}', median_label='\\mathrm{Median}', logx=False, logy=False, colors=['steelblue', 'darkturquoise', 'mediumturquoise'], fig=None)[source]¶
Plot a 1D distribution along with samples from the true distribution (if available). Differently from plot_median_cr, this method requires the distribution to be already evaluated. For FIGARO mixture instances, please use plot_median_cr.
- Parameters:
x (iterable) – values at which realisations are evaluated
draws (iterable) – container for realisations
injected (callable or np.ndarray) – injected distribution (if available)
samples (np.ndarray) – samples from the true distribution (if available)
out_folder (str or Path) – output folder
name (str) – name to be given to outputs
label (str) – LaTeX-style quantity label, for plotting purposes
unit (str) – LaTeX-style quantity unit, for plotting purposes
save (bool) – whether to save the plots or not
show (bool) – whether to show the plots during the run or not
subfolder (bool) – whether to save the plots in different subfolders (for multiple events)
true_value (float) – true value to infer
true_value_label (str) – label to assign to the true value marker
injected_label (str) – label to assign to the injected distribution
median_label (str) – label to assign to the median distribution
logx (bool) – x log scale
logy (bool) – y log scale
colors (list-of-str) – list of colors for median, 68% and 90% credible regions
fig (matplotlib.figure.Figure) – figure to use for plotting.
- figaro.plot.plot_median_cr(draws, injected=None, samples=None, selfunc=None, bounds=None, out_folder='.', name='density', n_pts=1000, label=None, unit=None, hierarchical=False, show=False, save=True, subfolder=False, true_value=None, true_value_label='\\mathrm{True\\ value}', injected_label='\\mathrm{Simulated}', median_label=None, fig=None, colors=['steelblue', 'darkturquoise', 'mediumturquoise'])[source]¶
Plot the recovered 1D distribution along with the injected distribution and samples from the true distribution (both if available).
- Parameters:
draws (iterable) – container for mixture instances
injected (callable or np.ndarray) – injected distribution (if available)
samples (np.ndarray) – samples from the true distribution (if available)
selfunc (callable or np.ndarray) – selection function (if available)
bounds (iterable) – bounds for the recovered distribution. If None, bounds from mixture instances are used.
out_folder (str or Path) – output folder
name (str) – name to be given to outputs
n_pts (int) – number of points for linspace
label (str) – LaTeX-style quantity label, for plotting purposes
unit (str) – LaTeX-style quantity unit, for plotting purposes
hierarchical (bool) – hierarchical inference, for plotting purposes
save (bool) – whether to save the plots or not
show (bool) – whether to show the plots during the run or not
subfolder (bool) – whether to save the plots in different subfolders (for multiple events)
true_value (float) – true value to infer
true_value_label (str) – label to assign to the true value marker
injected_label (str) – label to assign to the injected distribution
median_label (str) – label to assign to the reconstruction
fig (matplotlib.figure.Figure) – figure to use for plotting.
colors (list-of-str) – list of colors for median, 68% and 90% credible regions
- Returns:
figure with the plot
- Return type:
matplotlib.figure.Figure
- figaro.plot.plot_multidim(draws, samples=None, bounds=None, out_folder='.', name='density', labels=None, units=None, hierarchical=False, show=False, save=True, subfolder=False, n_pts=200, true_value=None, levels=[0.5, 0.68, 0.9], scatter_points=False, median_label=None, fig=None, colors=['steelblue', 'darkturquoise', 'mediumturquoise'], colormap='Blues')[source]¶
Plot the recovered multidimensional distribution along with samples from the true distribution (if available) as corner plot.
- Parameters:
draws (iterable) – container for mixture instances
samples (np.ndarray) – samples from the true distribution (if available)
bounds (iterable) – bounds for the recovered distribution. If None, bounds from mixture instances are used.
out_folder (str or Path) – output folder
name (str) – name to be given to outputs
labels (list-of-str) – LaTeX-style quantity label, for plotting purposes
units (list-of-str) – LaTeX-style quantity unit, for plotting purposes
hierarchical (bool) – hierarchical inference, for plotting purposes
save (bool) – whether to save the plot or not
show (bool) – whether to show the plot during the run or not
subfolder (bool) – whether to save in a dedicated subfolder
n_pts (int) – number of grid points (same for each dimension)
true_value (iterable) – true value to plot
levels (iterable) – credible levels to plot
scatter_points (bool) – scatter samples on 2d plots
median_label (str) – label to assign to the reconstruction
fig (matplotlib.figure.Figure) – figure to use for plotting. Must have (dim,dim) axes.
colors (list-of-str) – list of colors for median, 68% and 90% credible regions
colormap (str) – colormap for contour plots
- Returns:
figure with the plot
- Return type:
matplotlib.figure.Figure
- figaro.plot.plot_n_clusters_alpha(n_cl, alpha, out_folder='.', name='event', show=False, save=True)[source]¶
Plot the number of clusters and the concentration parameter as functions of the number of samples.
- Parameters:
n_cl (np.ndarray) – number of active clusters
alpha (np.ndarray) – concentration parameter
out_folder (str or Path) – output folder
name (str) – name to be given to outputs
save (bool) – whether to save the plot or not
show (bool) – whether to show the plot during the run or not
- figaro.plot.pp_plot_cdf(draws, injection, n_points=1000, out_folder='.', name='event', show=False, save=True)[source]¶
Make pp-plot comparing draws cdfs and injection cdf
- Parameters:
draws (iterable) – container of mixture instances
injection (callable) – injected density
n_points (int) – number of points for linspace
out_folder (str or Path) – output folder
name (str) – name to be given to outputs
save (bool) – whether to save the plot or not
show (bool) – whether to show the plot during the run or not
- figaro.plot.pp_plot_levels(CR_levels, median_CR=None, out_folder='.', name='MDC', show=False, save=True, fig=None, color='steelblue')[source]¶
Make pp-plot.
- Parameters:
CR (iterable) – 2D array with credible levels for each event
median_CR (iterable) – credible levels of medians
out_folder (str or Path) – output folder
name (str) – name to be given to outputs
save (bool) – whether to save the plot or not
show (bool) – whether to show the plot during the run or not
fig (matplotlib.figure.Figure) – figure to use for plotting.
color (str) – color for the main line