Bases: object
Base class to produce plots. Parameters defined for this class are used for all plots that are added to the figure. If you want to change the parameters for a specific plot, you can do so by passing the parameters to the plotting function.
fig – matplotlib figure, default: None
size – size of the panels, default: 4
params – list of parameters to plot, default: “all”
params_from – sample or list of samples from which the parameters should be taken, default: None
ranges – dictionary with the ranges for the parameters
names – list of names of the parameters, only used when input data is unstructured array
labels – list of labels (e.g. latex style) for the parameters for the plot
fill – if the contours should be filled, default: False
grid – if the grid should be plotted, default: False
tri – if upper or lower triangle should be plotted, default: “lower”
orientation – orientation for LineChain, default: “horizontal”
line_space – space between lines in LineChain, default: 0.5
plot_histograms_1D – if the 1D histograms should be plotted, default: True
n_ticks – number of ticks on the axes, default: 3
ticks – dict specifying the ticks for a parameter
tick_length – length of the ticks, default: 3
show_values – if best-fit and uncertainty should be given, default: False
bestfit_method – method for the best_fit, options: “mode”, “mean”, “median”, “best_sample” (requires lnprobs), default: “mode”
levels_method – method to compute the uncertainty bands, options: “hdi”, “percentile”, “PJ-HPD” (requires lnprobs), default: “hdi”
credible_interval – credible interval for the uncertainty, default: 0.68
n_sigma_for_one_sided_tail – number of sigma for the one-sided tail, default: 3
n_bins – number of bins for the 1D histograms, default: 100
density_estimation_method –
method for density estimation. Available options:
First create a histogram of samples and then smooth it with a Gaussian kernel corresponding to the variance of the 20% of the smallest eigenvalue of the 2D distribution (smoothing scale can be adapted using the smoothing parameter in de_kwargs).
Use Gaussian mixture to fit the 2D samples.
Use median filter on the 2D histogram.
Use TreeKDE, may be slow.
Simple 2D histogram.
cmap – colormap, default: “viridis”
colorbar – if a colorbar should be plotted, default: False
colorbar_label – label for the colorbar, default: None
colorbar_ax – axis for the colorbar, default: [0.735, 0.5, 0.03, 0.25]
cmap_vmin – minimum value for the colormap, default: 0
cmap_vmax – maximum value for the colormap, default: None
show_legend – if a legend should be shown, default: False
progress_bar – if a progress bar should be shown, default: True
alpha1D – alpha for the 1D histograms, default: 1
alpha2D – alpha for the 2D histograms, default: 1
alpha – alpha for the 2D histograms in LineChain, if passed to TriangleChain, overwrites the alpha1D and alpha2D value, default: 1
normalize_prob1D – if the 1D histograms should be normalized for scatter_prob, default: True
normalize_prob2D – if the 2D histograms should be normalized for scatter_prob, default: True
scatter_vline_1D – if a vertical line should be plotted in the 1D histograms for each point when using scatter, default: False
alpha_for_low_density – if low density areas should fade to transparent
alpha_threshold – threshold from where the fading to transparent should start, default: 0
n_points_scatter – number of points to use for scatter plots, default: -1 (all)
label_fontsize – fontsize of the labels, default: 24
de_kwargs –
density estimation kwargs, dictionary with keys:
number of bins for 2d histograms used to create contours etc., default: n_bins
density levels for contours, the contours will enclose this level of probability, default: [0.68, 0.95]
number of levels to check when looking for density levels More levels is more accurate, but slower, default: 2000
smoothing scale for the 1D histograms, default: 0.1
smoothing scale for the 2D histograms, default: 0.2
grid_kwargs –
kwargs for the plot grid, with keys:
font size for tick labels, default: 14
font family for tick labels, default: sans-serif
hist_kwargs – kwargs for the 1D histograms, passed to plt.hist function
labels_kwargs – kwargs for the x and y labels
line_kwargs – kwargs for the lines, passed to plt.contour and plt.contourf
scatter_kwargs – kwargs for the scatter plot, passed to plt.scatter
axvline_kwargs – kwargs for the vertical lines in the 1D histograms, passed to plt.axvline
subplots_kwargs – kwargs for the subplots, passed to plt.subplots
grouping_kwargs –
kwargs for grouping parameters in the plot with options:
how many parameters are grouped together (e.g. (3, 4, 5) for grouping the parameters accordingly), default: None
fraction of a whole plot that is left empty for separation, default: 0.2
Basic usage:
tri = TriangleChain()
# plot contours at given confidence levels
tri.contour_cl(samples)
# plot PDF density image
tri.density_image(samples)
# simple scatter plot
tri.scatter(samples)
# scatter plot, with probability for each sample provided
tri.scatter_prob(samples, prob=prob)
# scatter plot, color corresponds to probability
tri.scatter_density(samples)
Bases: BaseChain
Class to produce line plots. Parameters defined for this class are used for all plots that are added to the figure. If you want to change the parameters for a specific plot, you can do so by passing the parameters to the plotting function.
fig – matplotlib figure, default: None
size – size of the panels, if one number is given, the panels are rectangular with the y axis being 70% of the x axis, if two numbers are given, the first number is the width of the panels and the second number is the height of the panels, default: 4
params – list of parameters to plot, default: “all”
params_from – sample or list of samples from which the parameters should be taken, default: None
ranges – dictionary with the ranges for the parameters
names – list of names of the parameters, only used when input data is unstructured array
labels – list of labels (e.g. latex style) for the parameters for the plot
fill – if the contours should be filled, default: False
grid – if the grid should be plotted, default: False
n_ticks – number of ticks on the axes, default: 3
ticks – dict specifying the ticks for a parameter
tick_length – length of the ticks, default: 3
n_bins – number of bins for the 1D histograms, default: 100
density_estimation_method –
method for density estimation. Available options:
First create a histogram of samples and then smooth it with a Gaussian kernel corresponding to the variance of the 20% of the smallest eigenvalue of the 2D distribution (smoothing scale can be adapted using the smoothing parameter in de_kwargs).
Use Gaussian mixture to fit the 2D samples.
Use median filter on the 2D histogram.
Use TreeKDE, may be slow.
Simple 2D histogram.
cmap – colormap, default: “viridis”
colorbar – if a colorbar should be plotted, default: False
colorbar_label – label for the colorbar, default: None
colorbar_ax – axis for the colorbar, default: [0.735, 0.5, 0.03, 0.25]
cmap_vmin – minimum value for the colormap, default: 0
cmap_vmax – maximum value for the colormap, default: None
show_legend – if a legend should be shown, default: False
alpha – alpha for the 2D histograms, default: 1
alpha_for_low_density – if low density areas should fade to transparent
alpha_threshold – threshold from where the fading to transparent should start, default: 0
n_points_scatter – number of points to use for scatter plots, default: -1 (all)
label_fontsize – fontsize of the labels, default: 24
de_kwargs –
density estimation kwargs, dictionary with keys:
number of bins for 2d histograms used to create contours etc., default: n_bins
density levels for contours, the contours will enclose this level of probability, default: [0.68, 0.95]
number of levels to check when looking for density levels More levels is more accurate, but slower, default: 2000
smoothing scale for the 1D histograms, default: 0.1
smoothing scale for the 2D histograms, default: 0.2
grid_kwargs –
kwargs for the plot grid, with keys:
font size for tick labels, default: 14
font family for tick labels, default: sans-serif
labels_kwargs – kwargs for the x and y labels
line_kwargs – kwargs for the lines, passed to plt.contour and plt.contourf
scatter_kwargs – kwargs for the scatter plot, passed to plt.scatter
subplots_kwargs – kwargs for the subplots, passed to plt.subplots
Basic usage:
line = LineChain()
# plot contours at given confidence levels
line.contour_cl(samples)
# plot PDF density image
line.density_image(samples)
# simple scatter plot
line.scatter(samples)
# scatter plot, with probability for each sample provided
line.scatter_prob(samples, prob=prob)
# scatter plot, color corresponds to probability
line.scatter_density(samples)
Plotting function for the line chain class. Parameters that are passed to this function are overwriting the default parameters of the class.
data – data to plot, can be recarray, array, pandas dataframe or dict
prob – probability for each sample, default: None
color – color for the plot, default: None
label – label for the plot, default: None
names – list of names of the parameters, only used when input is unstructured array
fill – if the contours should be filled, default: False
grid – if the grid should be plotted, default: False
n_bins – number of bins for the 1D histograms, default: 100
density_estimation_method –
method for density estimation. Available options:
First create a histogram of samples and then smooth it with a Gaussian kernel corresponding to the variance of the 20% of the smallest eigenvalue of the 2D distribution (smoothing scale can be adapted using the smoothing parameter in de_kwargs).
Use Gaussian mixture to fit the 2D samples.
Use median filter on the 2D histogram.
Use TreeKDE, may be slow.
Simple 2D histogram.
cmap – colormap, default: “viridis”
colorbar – if a colorbar should be plotted, default: False
colorbar_label – label for the colorbar, default: None
colorbar_ax – axis for the colorbar, default: [0.735, 0.5, 0.03, 0.25]
cmap_vmin – minimum value for the colormap, default: 0
cmap_vmax – maximum value for the colormap, default: None
show_legend – if a legend should be shown, default: False
alpha – alpha for the 2D histograms, default: 1
normalize_prob2D – if the 2D histograms should be normalized for scatter_prob, default: True
alpha_for_low_density – if low density areas should fade to transparent
alpha_threshold – threshold from where the fading to transparent should start, default: 0
n_points_scatter – number of points to use for scatter plots, default: -1 (all)
de_kwargs –
density estimation kwargs, dictionary with keys:
number of bins for 2d histograms used to create contours etc., default: n_bins
density levels for contours, the contours will enclose this level of probability, default: [0.68, 0.95]
number of levels to check when looking for density levels More levels is more accurate, but slower, default: 2000
smoothing scale for the 1D histograms, default: 0.1
smoothing scale for the 2D histograms, default: 0.2
grid_kwargs –
kwargs for the plot grid, with keys:
font size for tick labels, default: 14
font family for tick labels, default: sans-serif
labels_kwargs – kwargs for the x and y labels
line_kwargs – kwargs for the lines, passed to plt.contour and plt.contourf
scatter_kwargs – kwargs for the scatter plot, passed to plt.scatter
subplots_kwargs – kwargs for the subplots, passed to plt.subplots
Get all pairs of parameters.
n_output – number of parameters
Plot line plots of chains.
data – rec array, array, dict or pd dataframe data to plot
prob – probability for each sample
params – parameters to plot, default: “all”
params_from – chain to get parameters from, default: None
names – names of parameters (when data is np array), default: None
func – function to use for plotting options: contour_cl, density_image, scatter_density, scatter_prob, scatter default: contour_cl
orientation – orientation of the plots, options: horizontal, vertical default: horizontal
color – color of the plot, default: “#0063B9”
cmap – colormap for 2D plots, default: plt.cm.viridis
cmap_vmin – minimum value for colormap, default: 0
cmap_vmax – maximum value for colormap, default: None
colorbar – show colorbar, default: False
colorbar_label – label for colorbar, default: None
colorbar_ax – position of colorbar, default: [0.735, 0.5, 0.03, 0.25]
ranges – dictionary with ranges for each parameter, default: {}
ticks – dictionary with ticks for each parameter, default: {}
n_ticks – number of ticks for each parameter, default: 3
tick_length – length of ticks, default: 3
n_bins – number of bins for histograms, default: 20
fig – figure to plot on, default: None
size – size of the figure, default: 4
fill – fill the area of the contours, default: True
grid – show grid, default: False
labels – labels for each parameter, default: None if None, labels are taken from the parameter names
label – label for the plot, default: None
label_fontsize – fontsize of the label, default: 12
show_legend – show legend, default: False
line_space – space between plots, default: 0.5
density_estimation_method – method to use for density estimation options: smoothing, histo, kde, gaussian_mixture, median_filter default: smoothing
alpha – alpha value for the plot, default: 1
alpha_for_low_density – use alpha for low density regions, default: False
alpha_threshold – threshold for alpha, default: 0
subplots_kwargs – kwargs for plt.subplots, default: {}
de_kwargs – kwargs for density estimation, default: {}
labels_kwargs – kwargs for labels, default: {}
grid_kwargs – kwargs for grid, default: {}
line_kwargs – kwargs for line plots, default: {}
scatter_kwargs – kwargs for scatter plots, default: {}
normalize_prob2D – normalize probability for 2D plots, default: True
n_points_scatter – number of points for scatter plots, default: -1 (all)
kwargs – additional kwargs for the plot function
fig, axes
Bases: BaseChain
Class to produce triangle plots. Parameters defined for this class are used for all plots that are added to the figure. If you want to change the parameters for a specific plot, you can do so by passing the parameters to the plotting function.
fig – matplotlib figure, default: None
size – size of the panels, if one number is given, the panels are square, if two numbers are given, the figure is rectangular, default: 4
params – list of parameters to plot, default: “all”
params_from – sample or list of samples from which the parameters should be taken, default: None
ranges – dictionary with the ranges for the parameters
names – list of names of the parameters, only used when input data is unstructured array
labels – list of labels (e.g. latex style) for the parameters for the plot
fill – if the contours should be filled, default: False
grid – if the grid should be plotted, default: False
tri – if upper or lower triangle should be plotted, default: “lower”
plot_histograms_1D – if the 1D histograms should be plotted, default: True
n_ticks – number of ticks on the axes, default: 3
ticks – dict specifying the ticks for a parameter
tick_length – length of the ticks, default: 3
show_values – if best-fit and uncertainty should be given, default: False
bestfit_method – method for the best_fit, options: “mode”, “mean”, “median”, “best_sample” (requires lnprobs), default: “mode”
levels_method – method to compute the uncertainty bands, options: “hdi”, “percentile”, “PJ-HPD” (requires lnprobs), default: “hdi”
credible_interval – credible interval for the uncertainty, default: 0.68
n_sigma_for_one_sided_tail – number of sigma for the one-sided tail, default: 3
n_bins – number of bins for the 1D histograms, default: 100
density_estimation_method –
method for density estimation. Available options:
First create a histogram of samples and then smooth it with a Gaussian kernel corresponding to the variance of the 20% of the smallest eigenvalue of the 2D distribution (smoothing scale can be adapted using the smoothing parameter in de_kwargs).
Use Gaussian mixture to fit the 2D samples.
Use median filter on the 2D histogram.
Use TreeKDE, may be slow.
Simple 2D histogram.
cmap – colormap, default: “viridis”
colorbar – if a colorbar should be plotted, default: False
colorbar_label – label for the colorbar, default: None
colorbar_ax – axis for the colorbar, default: [0.735, 0.5, 0.03, 0.25]
cmap_vmin – minimum value for the colormap, default: 0
cmap_vmax – maximum value for the colormap, default: None
show_legend – if a legend should be shown, default: False
progress_bar – if a progress bar should be shown, default: True
alpha – alpha for the plots, overwrite alpha1D and alpha2D, default: None
alpha1D – alpha for the 1D histograms, default: 1
alpha2D – alpha for the 2D histograms, default: 1
normalize_prob1D – if the 1D histograms should be normalized for scatter_prob, default: True
normalize_prob2D – if the 2D histograms should be normalized for scatter_prob, default: True
scatter_vline_1D – if a vertical line should be plotted in the 1D histograms for each point when using scatter, default: False
alpha_for_low_density – if low density areas should fade to transparent
alpha_threshold – threshold from where the fading to transparent should start, default: 0
n_points_scatter – number of points to use for scatter plots, default: -1 (all)
label_fontsize – fontsize of the labels, default: 24
de_kwargs –
density estimation kwargs, dictionary with keys:
number of bins for 2d histograms used to create contours etc., default: n_bins
density levels for contours, the contours will enclose this level of probability, default: [0.68, 0.95]
number of levels to check when looking for density levels More levels is more accurate, but slower, default: 2000
smoothing scale for the 1D histograms, default: 0.1
smoothing scale for the 2D histograms, default: 0.2
grid_kwargs –
kwargs for the plot grid, with keys:
font size for tick labels, default: 14
font family for tick labels, default: sans-serif
hist_kwargs – kwargs for the 1D histograms, passed to plt.hist function
labels_kwargs – kwargs for the x and y labels
line_kwargs – kwargs for the lines, passed to plt.contour and plt.contourf
scatter_kwargs – kwargs for the scatter plot, passed to plt.scatter
axvline_kwargs – kwargs for the vertical lines in the 1D histograms, passed to plt.axvline
subplots_kwargs – kwargs for the subplots, passed to plt.subplots
grouping_kwargs –
kwargs for grouping parameters in the plot with options:
how many parameters are grouped together (e.g. (3, 4, 5) for grouping the parameters accordingly), default: None
fraction of a whole plot that is left empty for separation, default: 0.2
Basic usage:
tri = TriangleChain()
# plot contours at given confidence levels
tri.contour_cl(samples)
# plot PDF density image
tri.density_image(samples)
# simple scatter plot
tri.scatter(samples)
# scatter plot, with probability for each sample provided
tri.scatter_prob(samples, prob=prob)
# scatter plot, color corresponds to probability
tri.scatter_density(samples)
Plotting function for the triangle chain class. Parameters that are passed to this function are overwriting the default parameters of the class.
data – data to plot, can be recarray, array, pandas dataframe or dict
prob – probability for each sample, default: None
color – color for the plot, default: None
label – label for the plot, default: None
lnprobs – lnprob for each sample (used for some best-fit methods), default: None
names – list of names of the parameters, only used when input is unstructured array
fill – if the contours should be filled, default: False
grid – if the grid should be plotted, default: False
tri – if upper or lower triangle should be plotted, default: “lower”
plot_histograms_1D – if 1D histograms should be plotted, default: True
show_values – if best-fit and uncertainty should be given, default: False
bestfit_method – method for the best_fit, options: “mode”, “mean”, “median”, “best_sample” (requires lnprobs), default: “mode”
levels_method – method to compute the uncertainty bands, default: options: “hdi”, “percentile”, “PJ-HPD” (requires lnprobs), default: “hdi”
credible_interval – credible interval for the uncertainty, default: 0.68
n_sigma_for_one_sided_tail – number of sigma for the one-sided tail, default: 3
n_bins – number of bins for the 1D histograms, default: 100
density_estimation_method –
method for density estimation. Available options:
First create a histogram of samples and then smooth it with a Gaussian kernel corresponding to the variance of the 20% of the smallest eigenvalue of the 2D distribution (smoothing scale can be adapted using the smoothing parameter in de_kwargs).
Use Gaussian mixture to fit the 2D samples.
Use median filter on the 2D histogram.
Use TreeKDE, may be slow.
Simple 2D histogram.
cmap – colormap, default: “viridis”
colorbar – if a colorbar should be plotted, default: False
colorbar_label – label for the colorbar, default: None
colorbar_ax – axis for the colorbar, default: [0.735, 0.5, 0.03, 0.25]
cmap_vmin – minimum value for the colormap, default: 0
cmap_vmax – maximum value for the colormap, default: None
show_legend – if a legend should be shown, default: False
progress_bar – if a progress bar should be shown, default: True
alpha – alpha for the plots, overwrite alpha1D and alpha2D, default: None
alpha1D – alpha for the 1D histograms, default: 1
alpha2D – alpha for the 2D histograms, default: 1
normalize_prob1D – if the 1D histograms should be normalized for scatter_prob, default: True
normalize_prob2D – if the 2D histograms should be normalized for scatter_prob, default: True
scatter_vline_1D – if a vertical line should be plotted in the 1D histograms for each point when using scatter, default: False
alpha_for_low_density – if low density areas should fade to transparent
alpha_threshold – threshold from where the fading to transparent should start, default: 0
n_points_scatter – number of points to use for scatter plots, default: -1 (all)
de_kwargs –
density estimation kwargs, dictionary with keys:
number of bins for 2d histograms used to create contours etc., default: n_bins
density levels for contours, the contours will enclose this level of probability, default: [0.68, 0.95]
number of levels to check when looking for density levels More levels is more accurate, but slower, default: 2000
smoothing scale for the 1D histograms, default: 0.1
smoothing scale for the 2D histograms, default: 0.2
grid_kwargs –
kwargs for the plot grid, with keys:
font size for tick labels, default: 14
font family for tick labels, default: sans-serif
hist_kwargs – kwargs for the 1D histograms, passed to plt.hist function
labels_kwargs – kwargs for the x and y labels
line_kwargs – kwargs for the lines, passed to plt.contour and plt.contourf
scatter_kwargs – kwargs for the scatter plot, passed to plt.scatter
axvline_kwargs – kwargs for the vertical lines in the 1D histograms, passed to plt.axvline
subplots_kwargs – kwargs for the subplots, passed to plt.subplots
grouping_kwargs –
kwargs for grouping parameters in the plot with options:
how many parameters are grouped together (e.g. (3, 4, 5) for grouping the parameters accordingly), default: None
fraction of a whole plot that is left empty for separation, default: 0.2
Plot triangle plot with 1D and 2D histograms, contours, scatter plots, etc.
data – data to plot, can be a dictionary, a recarray or a pandas DataFrame
prob – probability of each point, default: None
func –
function to use for plotting, default: ‘contour_cl’, options:
contour_cl (default)
density_image
scatter_density
scatter_prob
scatter default
color – color for the plot, default: ‘#0063B9’
label – label for the plot, default: None
lnprobs – lnprob for each sample (used for some best-fit methods), default: None
fig – matplotlib figure, default: None
size – size of the panels, if one number is given, the panels are square, if two numbers are given, the figure is rectangular, default: 4
params – list of parameters to plot, default: ‘all’
params_from – sample or list of samples from which the parameters should be taken, default: None
ranges – dictionary with ranges for the parameters, default: {}
labels – list of labels (e.g. latex style) for the parameters for the plot
names – list of names of the parameters, only used when input data is unstructured array
fill – if the contours should be filled, default: False
grid – if the grid should be plotted, default: False
tri – if upper or lower triangle should be plotted, default: “lower”
plot_histograms_1D – if the 1D histograms should be plotted, default: True
n_ticks – number of ticks on the axes, default: 3
ticks – dict specifying the ticks for each parameter
tick_length – length of the ticks, default: 3
show_values – if best-fit and uncertainty should be given, default: False
bestfit_method – method to use for best-fit, options: “mode”, “mean”, “median”, “best_sample” (requires lnprobs), default: “mode”
levels_method – method to compute the uncertainty bands, options: “hdi”, “percentile”, “PJ-HPD” (requires lnprobs), default: “hdi”
credible_interval – credible interval for the uncertainty bands, default: 0.68
n_sigma_for_one_sided_tail – number of sigma for the one-sided tail, default: 3
n_bins – number of bins for the 1D histograms, default: 100
density_estimation_method – method to use for density estimation, default=”smoothing”
cmap – colormap, default: plt.cm.viridis
cmap_vmin – minimum value for the colormap, default: 0
cmap_vmax – maximum value for the colormap, default: None
colorbar – if a colorbar should be plotted, default: False
colorbar_label – label for the colorbar, default: None
colorbar_ax – position of the colorbar, default: [0.735, 0.5, 0.03, 0.25]
show_legend – if a legend should be plotted, default: False
progress_bar – if a progress bar should be shown, default: True
alpha – alpha for the plots, overwrite alpha1D and alpha2D, default: None
alpha1D – alpha for the 1D histograms, default: 1
alpha2D – alpha for the 2D histograms, default: 1
normalize_prob1D – if the 1D histograms should be normalized for scatter_prob, default: True
normalize_prob2D – if the 2D histograms should be normalized for scatter_prob, default: True
scatter_vline_1D – if a vertical line should be plotted in the 1D histograms for each point when using scatter, default: False
alpha_for_low_density – if low density areas should fade to transparent
alpha_threshold – threshold for the alpha for low density areas
alpha_threshold – threshold from where the fading to transparent should start, default: 0
n_points_scatter – number of points to plot when using scatter, default: -1 (all)
label_fontsize – fontsize for the labels, default: 24
de_kwargs – dict with kwargs for the density estimation, default: {}
grid_kwargs – dict with kwargs for the grid, default: {}
hist_kwargs – dict with kwargs for the 1D histograms, default: {}
labels_kwargs – dict with kwargs for the labels, default: {}
line_kwargs – dict with kwargs for the lines, default: {}
scatter_kwargs – dict with kwargs for the scatter plot, default: {}
axvline_kwargs – dict with kwargs for the vertical lines, default: {}
subplots_kwargs – dict with kwargs for the subplots, default: {}
grouping_kwargs – dict with kwargs for the grouping, default: {}
add_empty_plots_like – DEPRECATED, default: None
Get the sample with the highest log probability.
samples – rec array with samples
lnprobs – array with log probabilities of the samples
sample with the highest log probability
Get all the best likelihood estimates.
params_chain – rec array with samples
lnprobs – array with log probabilities of the samples
emu – emulator (or any function that returns the observable)
cl_fid – fiducial power spectrum
inv_C – inverse covariance matrix
ells – array with multipoles
lims – limits of the parameters
prior_ind – indices of the parameters with priors
gauss_mean – mean of the Gaussian priors
gauss_sigma – standard deviation of the Gaussian priors
just_names – if True, only return the names of the best likelihood estimates
use_best_n – number of best likelihood samples to use
both_minimization – if True, use both minimizations
flat_chi2minimization – if True, use chi2 minimization without Gaussian priors
array with best likelihood estimates
Get all the best likelihood estimates except the mode.
params_chain – rec array with samples
lnprobs – array with log probabilities of the samples
emu – emulator
cl_fid – fiducial power spectrum
inv_C – inverse covariance matrix
ells – array with multipoles
lims – limits of the parameters
prior_ind – indices of the parameters with priors
gauss_mean – mean of the Gaussian priors
gauss_sigma – standard deviation of the Gaussian priors
just_names – if True, only return the names of the best likelihood estimates
use_best_n – number of best likelihood samples to use
both_minimization – if True, use both minimizations
flat_chi2minimization – if True, use chi2 minimization without Gaussian priors
array with best likelihood estimates
Get the best likelihood value of the chain by minimizing the chi2.
params_chain – rec array with samples
lnprobs – array with log probabilities of the samples
emu – emulator of the power spectrum
cl_fid – fiducial power spectrum
inv_C – inverse covariance matrix
ells – ell values
lims – limits of the parameters
prior_ind – indices of the parameters with a gaussian prior
gauss_mean – mean of the gaussian prior
gauss_sigma – sigma of the gaussian prior
use_best_n – number of best samples to use for the minimization
bool if successful minimization, best likelihood value and best lnprob
Get the best likelihood value of the chain by maximizing the log probability.
params_chain – rec array with samples
lnprobs – array with log probabilities of the samples
best likelihood value
Get the best fit value each parameter of the sample.
samples – rec array with samples
lnprobs – array with log probabilities of the samples (optional, default: None)
bestfit_method – method to use for best fit, options: mode: mode of the distribution (default) mean: mean of the distribution median: median of the distribution best_sample: sample with the highest log probability
best fit value for each parameter
Get the mean and median best likelihood of the samples of the chain.
params_chain – rec array with samples
lnprobs – array with log probabilities of the samples
mean and median value of the 10 best likelihood samples
Get the mean and median of each parameter of the sample.
samples – rec array with samples
mean and median of each parameter
Get the confidence levels for a given density estimation
de – density estimation
levels – confidence levels
n_levels_check – number of levels to check
confidence levels
Get density estimation for 1D data
data – data to estimate density from
binedges – bin edges for the histogram
bincenters – bin centers for the histogram
lims – limits for the histogram
prob – weights for the data
method – Method for density estimation. Valid options are: - ‘smoothing’: First create a histogram of samples, and then smooth it with a Gaussian kernel corresponding to the variance of the 20% of the smallest eigenvalue of the 2D distribution (smoothing scale can be adapted using the smoothing_scale parameter). - ‘gaussian_mixture’: Fit a Gaussian mixture model to the data. - ‘median_filter’: Use a median filter to smooth the histogram. - ‘kde’: Use a kernel density estimation to estimate the density. - ‘hist’: Use a histogram to estimate the density.
de_kwargs – keyword arguments for the density estimation method
density estimation
Get density estimation for 2D data
data – data to estimate density from
ranges – ranges for the data
columns – columns to use for the data
i – index of the first column
j – index of the second column
prob – weights for the data
method – Method for density estimation. Valid options are: - ‘smoothing’: First create a histogram of samples, and then smooth it with a Gaussian kernel corresponding to the variance of the 20% of the smallest eigenvalue of the 2D distribution (smoothing scale can be adapted using the smoothing_scale parameter). - ‘gaussian_mixture’: Fit a Gaussian mixture model to the data. - ‘median_filter’: Use a median filter to smooth the histogram. - ‘kde’: Use a kernel density estimation to estimate the density. - ‘hist’: Use a histogram to estimate the density.
de_kwargs – keyword arguments for the density estimation method
density estimation
Returns the upper and lower limit using projected joint highest posterior density. see arXiv:2007.01844
samples – np.ndarray with the given samples
lnprobs – logprobability of the samples
credible_interval – which credible interval should be used, defaults to 0.68
interpolator – interpolation function, defaults to utils_pj_hpd.interpolate
interp_kwargs – kwargs for the interpolation function
upper and lower limit
Get the cumulative distribution function.
samples – np.ndarray with the given samples
value – value to compute the cdf
cdf
Check if the credible interval is two tailed or one tailed.
samples – np.ndarray with the given samples
credible_interval – which credible interval should be used, defaults to 0.68
sigma_one_tail – how many sigma should be used to decide if one tailed credible interval should be used defaults to 3
True if two tailed, False if one tailed; if one tailed, if upper or lower
Get the upper and lower level of the credible interval. If the credible interval is two tailed, the upper and lower level are returned. If the credible interval is one tailed, only the lower/upper level is returned.
samples – np.ndarray with the given samples
lnprob – logprobability of the samples, used for some methods, defaults to None
levels_method – method how to compute the levels, options: “hdi”, “percentile”, “PJ_HPD”, defaults to “hdi”
credible_interval – which credible interval should be used, defaults to 0.68
sigma_one_tail – how many sigma should be used to decide if one tailed credible interval should be used defaults to 3
upper and lower limit (or only lower/upper limit if one tailed)
Get the upper or lower level of the credible interval.
samples – np.ndarray with the given samples
credible_interval – which credible interval should be used, defaults to 0.68
side – “upper” or “lower” side of the credible interval
upper or lower limit
Get the upper and lower level of the credible interval.
samples – np.ndarray with the given samples
lnprob – logprobability of the samples, used for some methods, defaults to None
levels_method – method how to compute the levels, options: “hdi”, “percentile”, “PJ_HPD”, defaults to “hdi”
credible_interval – which credible interval should be used, defaults to 0.68
upper and lower limit
Get the uncertainty band.
lower – lower limit
upper – upper limit
uncertainty band
Returns the upper and lower limit using highest density interval
samples – np.ndarray with the given samples
credible_interval – which credible interval should be used, defaults to 0.68
upper and lower limit
Returns the upper and lower percentile.
samples – np.ndarray with the given samples
credible_interval – which credible interval should be used, defaults to 0.68
upper and lower limit
Add values of bestfit and uncertainty to the plot.
axc – matplotlib axis axis of the plot
column – str name of the parameter in data that is plotted
data – numpy struct array the data that should be plotted with column data
lnprobs – array logprobabilites used for the bestfit and uncertainty finding
label – str label of the plot
levels_method – {“hdi”, “percentile”, “PJ_HPD”} method how to compute the uncertainty, default is hdi
bestfit_method – {“mode”, “mean”, “median”, “best_sample”} method how to compute the bestfit, default is mean
credible_interval – float in [0, 1] credible interval of the uncertainty bar, default is 0.68
sigma_one_tail – how many sigma should be used to decide if one tailed credible interval should be used defaults to 3
label_fontsize – int or float fontsize of the label of the parameters, default is 12
Plot the density of the data in the given axis as a contour plot.
axc – matplotlib axis axis of the plot
data – numpy struct array the data that should be plotted with column data
ranges – dict dictionary with the ranges of of the plot for each parameter
columns – list list of all parameters
i – int index of the first column to plot
j – int index of the second column to plot
fill – bool if the contour should be filled
color – str color of the contour
de_kwargs – dict dict with kde settings, has to have n_points, n_levels_check, levels
line_kwargs – dict dict with line settings, has to have linewidth, linestyle
prob – None or array if not None, then probability attached to the samples, in that case samples are treated as grid not a chain
density_estimation_method – {“gaussian_mixture”, “smoothing”, “median_filter”, “kde”, “hist”} method how to estimate the density
label – str label of the plot
alpha – float alpha value of the contour
Plot the density of the data in the given axis as a density image.
axc – matplotlib axis axis of the plot
data – numpy struct array the data that should be plotted with column data
ranges – dict dictionary with the ranges of of the plot for each parameter
columns – list list of all parameters
i – int index of the first column to plot
j – int index of the second column to plot
cmap – matplotlib colormap colormap that is used
de_kwargs – dict dict with kde settings, has to have n_points, n_levels_check, levels
vmin – None or float minimum value for the density (default=0) if None, the minimum in each subplot will be chosen as vmin
vmax – float maximum value for the density (default=None), if None, the maximum in each subplot will be chosen as vmax
prob – None or array if not None, then probability attached to the samples, in that case samples are treated as grid not a chain
density_estimation_method – {“gaussian_mixture”, “smoothing”, “median_filter”, “kde”, “hist”} method how to estimate the density
label – str label of the plot
alpha_for_low_density – bool if low density should fade out using alpha values
alpha_treshold – float in [0, 1] fraction of sample where alpha value should reach 1 0 means alpha is 1 everywhere 1 means linear decrease of alpha from 0 to 1 over the whole range
Plot 1D histogram and density estimation.
axc – matplotlib axis axis of the plot
column – str name of the parameter in data that is plotted
param_label – str name of the parameter that should be plotted in case bestfit and uncertainty are shown
data – numpy struct array the data that should be plotted with column data
prob – None or array if not None, then probability attached to the samples, in that case samples are treated as grid not a chain
ranges – dict dictionary with the ranges of of the plot for each parameter
current_ranges – dict dictionary with the current ranges of of the plot for each parameter
hist_binedges – array edges of the histogram for the plot
hist_bincenters – array centers of the histogram for the plot
de_kwargs – dict additional kwargs for density estimation, passed to get_density_grid
hist_kwargs – dict additional kwargs for the histogram plot, passed to plt.plot()
empty_columns – list list with the indices of empty columns
show_values – bool if values of bestfit and uncertainty should be plotted
label – str label of the plot
density_estimation_method – {“gaussian_mixture”, “smoothing”, “median_filter”, “kde”, “hist”} method how to estimate the density
color_hist – color color of the histogram
alpha1D – float in [0, 1] alpha value of the histogram
fill – bool use filled histograms
lnprobs – array logprobabilites used for the bestfit and uncertainty finding
levels_method – {“hdi”, “percentile”, “PJ_HPD”} method how to compute the uncertainty
bestfit_method – {“mode”, “mean”, “median”, “best_sample”} method how to compute the bestfit
credible_interval – float in [0, 1] credible interval of the uncertainty bar
sigma_one_tail – how many sigma should be used to decide if one tailed credible interval should be used defaults to 3
label_fontsize – int or float fontsize of the label of the parameters
Plot the density of the data in the given axis as a scatter plot. The color of the scatter points is determined by the density of the points.
axc – matplotlib axis axis of the plot
points1 – numpy array array of the first parameter
points2 – numpy array array of the second parameter
n_bins – int number of bins
lim1 – tuple limits of the first parameter
lim2 – tuple limits of the second parameter
n_points_scatter – int number of points to plot
label – str label of the plot
kwargs – dict dict with kwargs for the scatter plot
Adds a new derived parameter to the input data.
data (numpy.ndarray or dict or pandas.DataFrame) – The input data to add the derived parameter to. If a 2D numpy array, a pandas dataframe, or a dictionary of arrays, it will be converted to a recarray with automatically generated field names.
new_param (str) – The name of the new derived parameter to add.
derived (np.ndarray or list or float) – The derived value of the new parameter.
names (list of str, optional) – A list of field names to use if the input data is a 2D numpy array. The length of this list should match the number of columns in the array. If not provided, field names will be automatically generated.
The input data with the new derived parameter added.
numpy.recarray
Example usage:
>>> data = add_derived(data, "S8", data["sigma8"] * np.sqrt(data["omega_m"]/0.3))
Check if the names argument is used correctly.
names – A list of field names to use if the input data is a 2D numpy array.
data – The input data to check.
corrected names
Ensure that the input data is a numpy record array (recarray). If the input is already a recarray, it is returned as-is. If it is a 2D numpy array, a pandas dataframe, or a dictionary of arrays, it is converted to a recarray with automatically generated field names.
data (numpy.ndarray or dict or pandas.DataFrame) – The input data to ensure is a recarray. If a 2D numpy array, a pandas dataframe, or a dictionary of arrays, it will be converted to a recarray with automatically generated field names.
names (list of str, optional) – A list of field names to use if the input data is a 2D numpy array. The length of this list should match the number of columns in the array. If not provided, field names will be automatically generated.
column_prefix (str, optional) – A prefix to add to the automatically generated field names for the input data. This can be useful for distinguishing between multiple rec arrays with similar fields.
The input data as a recarray.
numpy.recarray
>>> data = np.array([[1, 2], [3, 4]])
>>> rec = ensure_rec(data)
>>> print(rec)
[(1, 2) (3, 4)]
>>> data_dict = {'a': [1, 2], 'b': [3, 4]}
>>> rec_dict = ensure_rec(data_dict)
>>> print(rec_dict)
[(1, 3) (2, 4)]
>>> data_names = np.array([[1, 2], [3, 4]])
>>> rec_names = ensure_rec(data_names, names=['x', 'y'])
>>> print(rec_names)
[(1, 2) (3, 4)]
>>> data_prefix = np.array([[1, 2], [3, 4]])
>>> rec_prefix = ensure_rec(data_prefix, column_prefix='data_')
>>> print(rec_prefix)
[(1, 2) (3, 4)]
>>> df = pd.DataFrame({'a': [1, 2], 'b': [3, 4]})
>>> rec_df = ensure_rec(df)
>>> print(rec_df)
[(1, 3) (2, 4)]
Get a random set of samples from a multivariate Gaussian distribution.
n_samples – The number of samples to generate.
n_dims – The number of dimensions of the samples.
names – A list of field names to use if the input data is a 2D numpy array. The length of this list should match the number of columns in the array. If not provided, field names will be automatically generated.
column_prefix – A prefix to add to the automatically generated field names for the input data.
covmat – The covariance matrix of the distribution.
mean – The mean of of each parameter in the distribution.
The samples.
Check if the integral of the function over the interval is above the threshold.
func – The function to integrate.
p_min – The minimum of the interval.
p_max – The maximum of the interval.
threshold – The threshold.
True if the integral is above the threshold, False otherwise.
Find the parameter value at which the integral of the function over the interval is above the threshold.
func – The function to integrate.
p_min – The minimum of the interval.
p_max – The maximum of the interval.
which_changed – A flag indicating if the minimum or maximum changed.
credible_interval – The credible interval.
The parameter value at which the integral is above the threshold.
Interpolate a histogram of the sample.
sample – The sample to interpolate.
bins – The number of bins to use for the histogram.
A function that can be used to evaluate the interpolated histogram.
Add a vertical line to the axes.
axc – The axes to add the line to.
column – The column of the data to add the line to.
data – The data which is used to add a line
color – The color of the line.
axvline_kwargs – The kwargs for the axvline.
Check the orientation of the axes of an previously created figure.
ax – The axes.
The orientation of the axes, either “upper”, “lower” or “both”.
Compute the plot limits.
x – The data to compute the limits for.
margin – The margin to add to the limits.
The limits.
Delete all ticks from the axes.
ax – The axes.
Find the alpha value for the column.
column – The column to find the alpha for.
empty_columns – The empty columns.
alpha – The alpha value.
The alpha value.
Find the optimal ticks for the given range.
range_of_param – The range of the parameter.
n_ticks – The number of ticks.
The ticks.
Get the best limits for the axes.
new_xlims – The new x limits.
new_ylims – The new y limits.
old_xlims – The old x limits.
old_ylims – The old y limits.
The best limits.
Get the best old limits of the axes. This is used to ensure that the limits of the axes are not changed when a new plot is added.
xlim1 – The old x-limits.
xlim2 – The new x-limits.
ylim1 – The old y-limits.
ylim2 – The new y-limits.
The best old limits.
Get the height/width ratios for the plots.
columns – The list of columns to be plotted.
grouping_kwargs – The grouping keyword arguments.
The new list of height/width ratios.
Get the labels for the plots. If no labels are given, the columns are used as labels.
labels – The labels to be used.
columns – The list of columns to be plotted.
grouping_indices – The grouping indices.
The new list of labels.
Get the lines and labels of the axes for the legend.
ax – The axes to get the lines and labels from.
The lines and labels.
Get the number of points to use for the scatter plot.
x – The x data.
y – The y data.
n_points_scatter – The number of points to use for the scatter plot. If -1, all points are used.
prob – The probability to use for the scatter plot.
The x, y and prob data.
Get the old limits of the axes.
axc – The axes.
The old limits.
Get the rounding digit and the format from PDG conventions.
uncertainty – The uncertainty.
The rounding digit and the format.
Get the smoothing sigma for the KDE.
x – The data to smooth.
max_points – The maximum number of points to use.
The smoothing sigma.
Get the values for the best fit and the uncertainty.
column – The column.
data – The data.
lnprobs – The log probabilities.
levels_method – The method to compute the uncertainty.
bestfit_method – The method to compute the best fit.
credible_interval – The credible interval.
sigma_one_tail – how many sigma should be used to decide if one tailed credible interval should be used defaults to 3
The best fit and the uncertainty.
Merge a list of lists into a new list, removing duplicates and maintaining the order of the elements.
lists – A list of input lists.
A new list with unique elements, maintaining the order of the elements.
Example: >>> lists = [[“a”, “b”, “c”], [“c”, “d”], [“e”, “f”, “g”], [“a”, “g”]] >>> merge_lists(lists) [‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’]
Normalise the array with x values.
y – The array.
x – The x values.
The normalised array.
Convert the coordinates to pixel coordinates.
x – The coordinates.
ranges – The ranges.
n_pix_img – The number of pixels.
The pixel coordinates.
Prepare the columns of the data to be plotted.
data – The data to plot.
params – The parameters to plot. If “all”, all parameters in the data will be plotted. If a list of strings, only the parameters with the given names will be plotted.
params_from – data to get the parameters from.
add_empty_plots_like – DEPRECATED: data to get the parameters from.
The data with only the columns to be plotted, the list of column names and the list of empty columns.
Round the number to the given number of significant digits.
number – The number.
significant_digits – The number of significant digits.
The rounded number.
Normalise the array without x values.
p – The array.
The normalised array.
Set the limits of the axes. If ranges are not specified, the range is determined automatically using current and previous plots.
axc – The axis to set the limits for.
ranges – The ranges to set. If not specified, the current ranges are used.
current_ranges – The current ranges.
col1 – The first column of the data.
col2 – The second column of the data.
old_xlims – previous limits of the x axis
old_ylims – previous limits of the y axis
Setup the figure.
fig – The figure to be used.
n_box – The number of boxes.
hw_ratios – The height/width ratios.
size – The size of the figure.
subplots_kwargs – The keyword arguments for the subplots.
The figure and the axes.
Setup the grouping of the plots.
columns – The list of columns to be plotted.
grouping_kwargs – The grouping keyword arguments.
The new list of columns, the grouping indices and the number of columns per group.
Update the current ranges of the data.
current_ranges – The current ranges.
ranges – The ranges.
columns – The list of columns to be plotted.
data – The data.
The new current ranges.
Update the current ticks of the data.
current_ticks – The current ticks.
columns – The list of columns to be plotted.
ranges – The ranges.
current_ranges – The current ranges.
n_ticks – The number of ticks.
The new current ticks.
This is the trianglechain package.