candl.plots#

Tools to plot that work together with the likelihood.

Warning:#

This is NOT a comprehensive plotting library. Instead, the functions below are largely designed as templates that you should modify for your specific purposes.

Overview:#

Helper for pretty LaTeX parameter labels and general plot style:

Showing the parameter covariance matrix:

Analysing minimisers:

Other:

candl.plots.PAR_LABEL_DICT = {'H0': 'H_{\\mathrm{0}}', 'S8': 'S_8 \\equiv \\sigma_8 \\sqrt{\\Omega_{\\mathrm{m}}/0.3}', 'age': '{\\mathrm{Age}}/{\\mathrm{Gyr}}', 'clamp': '10^9 A_{\\mathrm{s}} e^{-2\\tau}', 'ln10^{10}A_s': '\\log{ A_{\\mathrm{s}}}', 'logA': '\\log{ A_{\\mathrm{s}}}', 'n_s': 'n_{\\mathrm{s}}', 'ns': 'n_{\\mathrm{s}}', 'ombh2': '\\Omega_{\\mathrm{b}}h^2', 'omch2': '\\Omega_{\\mathrm{c}}h^2', 'omega_b': '\\Omega_{\\mathrm{b}}h^2', 'omega_cdm': '\\Omega_{\\mathrm{c}}h^2', 'omegal': '\\Omega_{\\mathrm{\\Lambda}}', 'sigma8': '\\sigma_8', 'tau': '\\tau', 'tau_reio': '\\tau', 'theta': '100\\theta_{\\mathrm{MC}}'}#

Dictionary of common names of and abbreviations for cosmological parameters and corresponding pretty latex strings.

candl.plots.add_confidence_ellipse(ax, this_cov, ix=0, jx=1, mean_x=0, mean_y=0, n_std=1, facecolor='none', **kwargs)#

Add a confidence based on the covariance matrix to ax. Based on matplotlib example code with some slight modifications. See: https://matplotlib.org/stable/gallery/statistics/confidence_ellipse.html

There may be a slight mix-up between ix/jx and mean_x/mean_y, worth trying out some permutations if you use this function by itself.

Parameters:
axmatplotlib.axes

The axes to add the ellipse to.

this_covarray

Parameter covariance matrix.

ixint

Index of first parameter.

jxint

Index of first parameter.

mean_xfloat

Where to centre the ellipse in x.

mean_yfloat

Where to centre the ellipse in y.

n_stdfloat

Which number of standard deviations to show.

facecolorstring/array

Facecolour of ellipse.

kwargs

Other arguments to be passed through to matplotlib.patches.Ellipse.

candl.plots.add_min_trajectory(ax, pars_to_plot, eval_points, par_cov, pars_in_cov, bf_point=None, base_colour='blue', dark_colours=False, markeredgewidth=0.25)#

Add the trajectory of a minimiser run to a triangle plot. Designed to work with plots created by triangle_plot_from_cov().

Parameters:
axmatplotlib.axes

The axes to add the ellipse to.

pars_to_plotlist

List of parameters to plot.

eval_pointslist

List of parameter dictionaries giving the minimiser steps.

par_covarray

Parameter covariance matrix. This is only needed to set the correct height of the points in the 1d panels.

bf_pointdict

This is only needed to set the correct height of the points in the 1d panels.

base_colourstr

Base colour for the series of points.

dark_coloursbool

Whether points should go from colour->black (default is colour->white).

markeredgewidthfloat

Thickness of the outline of points

candl.plots.plot_band_powers(like, show_legend=True, colour_by_spec_type=False)#

Plots the band powers for a given primary CMB likelihood.

Parameters:
likecandl.like

The likelihood.

show_legendbool (optional)

Whether to show the legend. Default is True.

colour_by_spec_type bool (optional)

Whether to colour the band powers by spectrum type. Default is False.

candl.plots.plot_foreground_components(like, fg_dict)#

Plot foreground components. Intended to be used with output from get_foreground_contributions() of candl.Like. Warning: this function is hardcoded for full ell range TT/TE/EE spectra 6 frequency combinations. If you have other needs please create a copy and modify it. This means this function can also not deal with cropped likelihoods.

Parameters:
likecandl.Like

Likelihood instance. Used to get effective ell centres, spectrum order and identifiers, etc.

fg_dictdict

Dictionary of spectra where each value is a dictionary holding the unbinned fg conitribution for a given source, i.e. the output of candl.Like.get_foreground_contributions() in the format “dict by spec”.

candl.plots.plot_mcmc_chain_steps(gd_samples, pars_to_plot, bf_point=None, par_cov=None, pars_in_cov=None, show_logl=True)#

Plot steps from an MCMC chain. Intended to be used in conjunction with getdist and Cobaya/CosmoMC.

Parameters:
gd_samplesgetdist.mcsamples.MCSamples

Samples instance containing all the parameter values.

pars_to_plotlist

List of strings of parameter names to plot.

bf_pointdict

Best-fit point to indicate.

par_covarray (float)

Parameter covariance matrix at the best-fit point.

pars_in_covlist

List of strings specifying the order of parameters in the covariance matrix.

show_loglbool

Whether to show the log likelihood values or not.

candl.plots.plot_minimiser_convergence(eval_points, pars_to_plot=None, par_cov=None, par_cov_order=None, relative=False)#

Plots the steps of the minimizer to help assess convergence.

Parameters:
eval_pointslist

List of dictionaries representing the evaluation points.

pars_to_plotlist, optional

List of parameters to plot. If None, all parameters in eval_points will be plotted.

par_covndarray, optional

Covariance matrix of the parameters. If provided, error bars will be plotted.

par_cov_orderlist, optional

Order of parameters in the covariance matrix. Required if par_cov is provided.

relativebool, optional

If True, the parameter values will be plotted relative to the last value and in units of the covariance. Default is False.

candl.plots.set_plot_style()#

Sets the plotting style. Important to unify things across figures and machines and generally makes plots prettier. Thank you to Federico Bianchini for this template!

candl.plots.triangle_plot_from_cov(pars_to_plot, bf_point, par_cov, pars_in_cov, sigma_plot_range=5, sigma_levels=2, ax=None, contour_colours=None, contour_edgecolour=None, zorder_offset=0, ls_1d='-', alpha_1d=1.0, alpha=1.0, set_axlims=True, return_handle=False, show_ticks=True, lw_1d=0.75, **kwargs)#

Create a triangle plot with contours. This can be called multiple times to add multiple data sets to one plot. For subsequent calls pass the axes instance and (you probably want to) set set_axlims=False.

Parameters:
pars_to_plotlist

List of parameters to plot.

bf_pointdict

Best-fit point, used to centre the confidence ellipses.

par_covarray

Parameter covariance matrix.

pars_in_covlist

List of parameters in par_cov.

sigma_plot_rangefloat

Used to set axes limits.

sigma_levelsint

How far out to show contours.

ax

if None makes new figure, if matplotlib.axes adds to passed axes.

contour_colours: str/array

Face colours of the contours.

contour_edgecolour: str/array

Edge colours of the contours.

zorder_offsetint

Offset to be applied to zorder of confidence ellipses. Handy to get right background/foreground ordering.

ls_1dstr

Linestyle for 1d panels.

alpha_1dfloat

Alpha for the 1d lines.

alphafloat

Alpha to be applied to the confidence ellipses.

set_axlimsbool

Whether to set the ax lims or not. Likely only want this the first time this function is called on a given ax instance.

return_handlebool

Whether to return a handle to create a legend with.

show_ticksbool

Whether to show ticks (switch off to blind results).

lw_1d: float

Linewidth for 1d panels.

kwargs:

Other arguments to be passed through to matplotlib.patches.Ellipse.