getdist.plots

This module is used for making plots from samples. The getSinglePlotter and getSubplotPlotter functions are used to make a plotter instance, which is then used to make and export plots.

Many plotter functions take a roots argument, which is either a root name for some chain files, or an in-memory MCSamples instance. You can also make comparison plots by giving a list of either of these.

Parameter are referenced simply by name (as specified in the .paramnames file when loading from file, or set in the MCSamples instance). For functions that takes lists of parameters, these can be just lists of names. You can also use glob patterns to match specific subsets of parameters (e.g. x* to match all parameters with names starting with x).

getSinglePlotter Get a GetDistPlotter for making a single plot of fixed width.
getSubplotPlotter Get a GetDistPlotter for making an array of subplots.
GetDistPlotter Main class for making plots from one or more sets of samples.
GetDistPlotSettings Settings class (colors, sizes, font, styles etc.)
exception getdist.plots.GetDistPlotError[source]

An exception that is raised when there is an error plotting

class getdist.plots.GetDistPlotSettings(subplot_size_inch=2, fig_width_inch=None)[source]

Settings class (colors, sizes, font, styles etc.)

Variables:
  • alpha_factor_contour_lines – alpha factor for adding contour lines between filled contours
  • alpha_filled_add – alpha for adding filled contours to a plot
  • axis_marker_color – The color for a marker
  • axis_marker_ls – The line style for a marker
  • axis_marker_lw – The line width for a marker
  • colorbar_label_pad – padding for the colorbar labels
  • colorbar_label_rotation – angle to rotate colorbar label (set to zero if -90 default gives layout problem)
  • colorbar_rotation – angle to rotate colorbar tick labels
  • colormap – a Matplotlib color map for shading
  • colormap_scatter

    a Matplotlib color map for 3D plots

  • default_dash_styles – dict mapping line styles to detailed dash styles, default: {‘–’: (3, 2), ‘-.’: (4, 1, 1, 1)}
  • fig_width_inch – The width of the figure in inches
  • figure_legend_frame – draw box around figure legend
  • figure_legend_loc – The location for the figure legend
  • figure_legend_ncol – number of columns for figure legend
  • legend_fontsize – The font size for the legend
  • legend_frac_subplot_line – fraction of _subplot size to use per line for spacing figure legend
  • legend_frac_subplot_margin – fraction of _subplot size to use for spacing figure legend above plots
  • legend_frame – draw box around legend
  • legend_loc – The location for the legend
  • legend_position_config – recipe for positioning figure border (default 1)
  • legend_rect_border – whether to have black border around solid color boxes in legends
  • line_labels – True if you want to automatically add legends when adding more than one line to subplots
  • lineM – list of default line styles/colors ([‘-k’,’-r’...])
  • no_triangle_axis_labels – whether subplots in triangle plots should show axis labels if not at the edge
  • norm_prob_label – label for the y axis in normalized 1D density plots
  • num_plot_contours – number of contours to plot in 2D plots (up to number of contours in analysis settings)
  • num_shades – number of distinct colors to use for shading shaded 2D plots
  • param_names_for_labels – file name of .paramnames file to use for overriding parameter labels for plotting
  • plot_args – dict, or list of dicts, giving settings like color, ls, alpha, etc. to apply for a plot or each line added
  • plot_meanlikes – include mean likelihood lines in 1D plots
  • prob_label – label for the y axis in unnormalized 1D density plots
  • prob_y_ticks – show ticks on y axis for 1D density plots
  • progress – write out some status
  • shade_level_scale – shading contour colors are put at [0:1:spacing]**shade_level_scale
  • shade_meanlikes – 2D shading uses mean likelihoods rather than marginalized density
  • solid_colors – List of default colors for filled 2D plots. Each element is either a color, or a tuple of values for different contour levels.
  • solid_contour_palefactor – factor by which to make 2D outer filled contours paler when only specifying one contour colour
  • tick_prune – None, ‘upper’ or ‘lower’ to prune ticks
  • tight_gap_fraction – fraction of plot width for closest tick to the edge
  • tight_layout – use tight_layout to lay out and remove white space
  • x_label_rotation – The rotation for the x label in degrees.

If fig_width_inch set, fixed setting for fixed total figure size in inches. Otherwise use subplot_size_inch to determine default font sizes etc., and figure will then be as wide as necessary to show all subplots at specified size.

Parameters:
  • subplot_size_inch – Determines the size of subplots, and hence default font sizes
  • fig_width_inch – The width of the figure in inches, If set, forces fixed total size.
rcSizes(axes_fontsize=None, lab_fontsize=None, legend_fontsize=None)[source]

Sets the font sizes by default from matplotlib.rcParams defaults

Parameters:
  • axes_fontsize – The font size for the plot axes tick labels (default: xtick.labelsize).
  • lab_fontsize – The font size for the plot’s axis labels (default: axes.labelsize)
  • legend_fontsize – The font size for the plot’s legend (default: legend.fontsize)
setWithSubplotSize(size_inch=3.5, size_mm=None)[source]

Sets the subplot’s size, either in inches or in millimeters. If both are set, uses millimeters.

Parameters:
  • size_inch – The size to set in inches; is ignored if size_mm is set.
  • size_mm – None if not used, otherwise the size in millimeters we want to set for the subplot.
class getdist.plots.GetDistPlotter(plot_data=None, chain_dir=None, settings=None, analysis_settings=None, mcsamples=True)[source]

Main class for making plots from one or more sets of samples.

Variables:
  • settings – a GetDistPlotSettings instance with settings
  • subplots – a 2D array of Axes for subplots
  • sampleAnalyser – a MCSampleAnalysis instance for getting MCSamples and derived data from a given root name tag (e.g. sampleAnalyser.samplesForRoot(‘rootname’))
Parameters:
  • plot_data – (deprecated) directory name if you have pre-computed plot_data/ directory from GetDist; None by default
  • chain_dir – Set this to a directory or grid root to search for chains (can also be a list of such, searched in order)
  • analysis_settings – The settings to be used by MCSampleAnalysis when analysing samples
  • mcsamples – if True defaults to current method of using MCSampleAnalysis instance to analyse chains on demand
add_1d(root, param, plotno=0, normalized=False, ax=None, **kwargs)[source]

Low-level function to add a 1D marginalized density line to a plot

Parameters:
  • root – The root name of the samples
  • param – The parameter name
  • plotno – The index of the line being added to the plot
  • normalized – True if areas under lines should match, False if normalized to unit maximum
  • ax – optional Axes instance to add to (defaults to current plot)
  • kwargs – arguments for plot()
Returns:

min, max for the plotted density

add_2d_contours(root, param1=None, param2=None, plotno=0, of=None, cols=None, contour_levels=None, add_legend_proxy=True, param_pair=None, density=None, alpha=None, ax=None, **kwargs)[source]

Low-level function to add 2D contours to plot for samples with given root name and parameters

Parameters:
  • root – The root name of samples to use
  • param1 – x parameter
  • param2 – y parameter
  • plotno – The index of the contour lines being added
  • of – the total number of contours being added (this is line plotno of of)
  • cols – optional list of colors to use for contours, by default uses default for this plotno
  • contour_levels – levels at which to plot the contours, by default given by contours array in the analysis settings
  • add_legend_proxy – True if should add a proxy to the legend of this plot.
  • param_pair – an [x,y] parameter name pair if you prefer to provide this rather than param1 and param2
  • density – optional Density2D to plot rather than that computed automatically from the samples
  • alpha – alpha for the contours added
  • ax – optional Axes instance to add to (defaults to current plot)
  • kwargs

    optional keyword arguments:

    • filled: True to make filled contours
    • color: top color to automatically make paling contour colours for a filled plot
    • kwargs for contour() and contourf()
Returns:

bounds (from bounds()) for the 2D density plotted

add_2d_density_contours(density, **kwargs)[source]

Low-level function to add 2D contours to a plot using provided density

Parameters:
Returns:

bounds (from bounds()) of density

add_2d_scatter(root, x, y, color='k', alpha=1, extra_thin=1, scatter_size=None, ax=None)[source]

Low-level function to adds a 2D sample scatter plot to the current axes (or ax if specified).

Parameters:
  • root – The root name of the samples to use
  • param1 – name of x parameter
  • param2 – name of y parameter
  • color – color to plot the samples
  • alpha – The alpha to use.
  • extra_thin – thin the weight one samples by this additional factor before plotting
  • scatter_size – point size (default: settings.scatter_size)
  • ax – optional Axes instance to add to (defaults to current plot)
Returns:

(xmin, xmax), (ymin, ymax) bounds for the axes.

add_2d_shading(root, param1, param2, colormap=None, density=None, ax=None, **kwargs)[source]

Low-level function to add 2D density shading to the given plot.

Parameters:
  • root – The root name of samples to use
  • param1 – x parameter
  • param2 – y parameter
  • colormap – color map, default to settings.colormap (see GetDistPlotSettings)
  • density – optional user-provided Density2D to plot rather than the auto-generated density from the samples
  • ax – optional Axes instance to add to (defaults to current plot)
  • kwargs – keyword arguments for contourf()
add_3d_scatter(root, params, color_bar=True, alpha=1, extra_thin=1, scatter_size=None, ax=None, **kwargs)[source]

Low-level function to add a 3D scatter plot to the current axes (or ax if specified).

Parameters:
  • root – The root name of the samples to use
  • params – list of parameters to plot
  • color_bar – True to add a colorbar for the plotted scatter color
  • alpha – The alpha to use.
  • extra_thin – thin the weight one samples by this additional factor before plotting
  • scatter_size – point size (default: settings.scatter_size)
  • ax – optional Axes instance to add to (defaults to current plot)
  • kwargs – arguments for add_colorbar()
Returns:

(xmin, xmax), (ymin, ymax) bounds for the axes.

add_colorbar(param, orientation='vertical', mappable=None, ax=None, **ax_args)[source]

Adds a color bar to the given plot.

Parameters:
  • param – a ParamInfo with label for the parameter the color bar is describing
  • orientation – The orientation of the color bar (default: ‘vertical’)
  • mappable – the thing to color, defaults to current scatter
  • ax – optional Axes instance to add to (defaults to current plot)
  • ax_args

    extra arguments -

    color_label_in_axes - if True, label is not added (insert as text label in plot instead)

Returns:

The new Colorbar instance

add_colorbar_label(cb, param, label_rotation=None)[source]

Adds a color bar label.

Parameters:
  • cb – a Colorbar instance
  • param – a ParamInfo with label for the plotted parameter
  • label_rotation – If set rotates the label (degrees)
add_legend(legend_labels, legend_loc=None, line_offset=0, legend_ncol=None, colored_text=False, figure=False, ax=None, label_order=None, align_right=False, fontsize=None)[source]

Add a legend to the axes or figure.

Parameters:
  • legend_labels – The labels
  • legend_loc – The legend location, default from settings
  • line_offset – The offset of plotted lines to label (e.g. 1 to not label first line)
  • legend_ncol – The number of columns in the legend, defaults to 1
  • colored_text
    • True: legend labels are colored to match the lines/contours
    • False: colored lines/boxes are drawn before black labels
  • figure – True if legend is for the figure rather than the selected axes
  • ax – if figure == False, the Axes instance to use; defaults to current axes.
  • label_order – minus one to show legends in reverse order that lines were added, or a list giving specific order of line indices
  • align_right – True to align legend text at the right
  • fontsize – The size of the font, default from settings
Returns:

a matplotlib.legend.Legend instance

add_line(xdata, ydata, zorder=0, color=None, ls=None, ax=None, **kwargs)[source]

Adds a line to the given axes, using Line2D

Parameters:
  • xdata – pair of x coordinates
  • ydata – pair of y coordinates
  • zorder – Z-order for Line2D
  • color – The color of the line, uses settings.axis_marker_color by default
  • ls – The line style to be used, uses settings.axis_marker_ls by default
  • ax – the Axes instance to use, defaults to current axes
  • kwargs – Additional arguments for Line2D
add_text(text_label, x=0.95, y=0.06, ax=None, **kwargs)[source]

Add text to given axis.

Parameters:
  • text_label – The label to add.
  • x – The x coordinate of where to add the label
  • y – The y coordinate of where to add the label.
  • ax – the Axes instance to use, index or [x,y] coordinate of subplot to use, or default to current axes.
  • kwargs – keyword arguments for text()
add_text_left(text_label, x=0.05, y=0.06, ax=None, **kwargs)[source]

Add text to the left, Wraps add_text.

Parameters:
  • text_label – The label to add.
  • x – The x coordinate of where to add the label
  • y – The y coordinate of where to add the label.
  • ax – the Axes instance to use, defaults to current axes.
  • kwargs – keyword arguments for text()
add_x_bands(x, sigma, color='gray', ax=None, alpha1=0.15, alpha2=0.1, **kwargs)[source]

Adds vertical shaded bands showing one and two sigma ranges.

Parameters:
  • x – central x value for bands
  • sigma – 1 sigma error on x
  • color – The base color to use
  • ax – optional Axes instance to add the bands to (defaults to current plot)
  • alpha1 – alpha for the 1 sigma band; note this is drawn on top of the 2 sigma band. Set to zero if you only want 2 sigma band
  • alpha2 – alpha for the 2 sigma band. Set to zero if you only want 1 sigma band
  • kwargs – optional keyword arguments for axvspan()
from getdist import plots, gaussian_mixtures
samples1, samples2 = gaussian_mixtures.randomTestMCSamples(ndim=2, nMCSamples=2)
g = plots.getSinglePlotter(width_inch=4)
g.plot_2d([samples1, samples2], ['x0','x1'], filled=False);
g.add_x_bands(0, 1)
_images/plots-1.png
add_x_marker(marker, color=None, ls=None, lw=None, ax=None, **kwargs)[source]

Adds a vertical line marking some x value. Optional arguments can override default settings.

Parameters:
  • marker – The x coordinate of the location the marker line
  • color – optional color of the marker
  • ls – optional line style of the marker
  • lw – optional line width
  • ax – optional Axes instance to add to (defaults to current plot)
  • kwargs – additional arguments to pass to axvline()
add_y_bands(y, sigma, color='gray', ax=None, alpha1=0.15, alpha2=0.1, **kwargs)[source]

Adds horizontal shaded bands showing one and two sigma ranges.

Parameters:
  • y – central y value for bands
  • sigma – 1 sigma error on y
  • color – The base color to use
  • ax – optional Axes instance to add the bands to (defaults to current plot)
  • alpha1 – alpha for the 1 sigma band; note this is drawn on top of the 2 sigma band. Set to zero if you only want 2 sigma band
  • alpha2 – alpha for the 2 sigma band. Set to zero if you only want 1 sigma band
  • kwargs – optional keyword arguments for axhspan()
from getdist import plots, gaussian_mixtures
samples= gaussian_mixtures.randomTestMCSamples(ndim=2, nMCSamples=1)
g = plots.getSinglePlotter(width_inch=4)
g.plot_2d(samples, ['x0','x1'], filled=True);
g.add_y_bands(0, 1)
_images/plots-2.png
add_y_marker(marker, color=None, ls=None, lw=None, ax=None, **kwargs)[source]

Adds a horizontal line marking some y value. Optional arguments can override default settings.

Parameters:
  • marker – The y coordinate of the location the marker line
  • color – optional color of the marker
  • ls – optional line style of the marker
  • lw – optional line width.
  • ax – optional Axes instance to add to (defaults to current plot)
  • kwargs – additional arguments to pass to axhline()
export(fname=None, adir=None, watermark=None, tag=None)[source]

Exports given figure to a file. If the filename is not specified, saves to a file with the same name as the calling script (useful for plot scripts where the script name matches the output figure).

Parameters:
  • fname – The filename to export to. The extension (.pdf, .png, etc) determines the file type
  • adir – The directory to save to
  • watermark – a watermark text, e.g. to make the plot with some pre-final version number
  • tag – A suffix to add to the filename.
finish_plot(legend_labels=None, legend_loc=None, line_offset=0, legend_ncol=None, label_order=None, no_gap=False, no_extra_legend_space=False, no_tight=False)[source]

Finish the current plot, adjusting subplot spacing and adding legend

Parameters:
  • legend_labels – The labels
  • legend_loc – The legend location, default from settings
  • line_offset – The offset of plotted lines to label (e.g. 1 to not label first line)
  • legend_ncol – The number of columns in the legend, defaults to 1
  • label_order – minus one to show legends in reverse order that lines were added, or a list giving specific order of line indices
  • no_gap – True if should leave no subplot padding in tight_layout
  • no_extra_legend_space – True to prevent making additional space above subplots for the legend
  • no_tight – don’t use tight_layout() to adjust subplot positions
get_param_array(root, params=None, renames={})[source]

Gets an array of ParamInfo for named params

Parameters:
  • root – The root name of the samples to use
  • params – the parameter names (if not specified, get all)
  • renames – optional dictionary mapping input names and equivalent names used by the samples
Returns:

list of ParamInfo instances for the parameters

make_figure(nplot=1, nx=None, ny=None, xstretch=1.0, ystretch=1.0)[source]

Makes a new figure.

Parameters:
  • nplot – number of subplots
  • nx – number of subplots in each row
  • ny – number of subplots in each column
  • xstretch – The parameter of how much to stretch the width, 1 is default
  • ystretch – The parameter of how much to stretch the height, 1 is default
Returns:

The plot_col, plot_row numbers of subplots for the figure

newPlot()[source]

Resets the given plotter to make a new empty plot.

paramBoundsForRoot(root)[source]

Get any hard prior bounds for the parameters with root file name

Parameters:root – The root name to be used
Returns:object with getUpper() and getLower() bounds functions
paramNamesForRoot(root)[source]

Get the parameter names and labels ParamNames instance for the given root name

Parameters:root – The root name of the samples.
Returns:ParamNames instance
param_latex_label(root, name, labelParams=None)[source]

Returns the latex label for given parameter.

Parameters:
  • root – root name of the samples having the parameter (or MCSamples instance)
  • name – The param name
  • labelParams – optional name of .paramnames file to override parameter name labels
Returns:

The latex label

plot_1d(roots, param, marker=None, marker_color=None, label_right=False, no_ylabel=False, no_ytick=False, no_zero=False, normalized=False, param_renames={}, **kwargs)[source]

Make a single 1D plot with marginalized density lines.

Parameters:
  • roots – root name or MCSamples instance (or list of any of either of these) for the samples to plot
  • param – the parameter name to plot
  • marker – If set, places a marker at given coordinate.
  • marker_color – If set, sets the marker color.
  • label_right – If True, label the y axis on the right rather than the left
  • no_ylabel – If True excludes the label on the y axis
  • no_ytick – If True show no y ticks
  • no_zero – If true does not show tick label at zero on y axis
  • normalized – plot normalized densities (if False, densities normalized to peak at 1)
  • param_renames – optional dictionary mapping input parameter names to equivalent names used by the samples
  • kwargs

    additional optional keyword arguments:

    • lims: optional limits for x range of the plot [xmin, xmax]
    • ls : list of line styles for the different lines plotted
    • colors: list of colors for the different lines plotted
    • lws: list of line widths for the different lines plotted
    • alphas: list of alphas for the different lines plotted
    • line_args: a list of dictionaries with settings for each set of lines
    • arguments for setAxes()
from getdist import plots, gaussian_mixtures
samples1, samples2 = gaussian_mixtures.randomTestMCSamples(ndim=2, nMCSamples=2)
g = plots.getSinglePlotter(width_inch=4)
g.plot_1d([samples1, samples2], 'x0', marker=0)
_images/plots-3.png
from getdist import plots, gaussian_mixtures
samples1, samples2 = gaussian_mixtures.randomTestMCSamples(ndim=2, nMCSamples=2)
g = plots.getSinglePlotter(width_inch=3)
g.plot_1d([samples1, samples2], 'x0', normalized=True, colors=['green','black'])
_images/plots-4.png
plot_2d(roots, param1=None, param2=None, param_pair=None, shaded=False, add_legend_proxy=True, line_offset=0, proxy_root_exclude=[], **kwargs)[source]

Create a single 2D line, contour or filled plot.

Parameters:
  • roots – root name or MCSamples instance (or list of any of either of these) for the samples to plot
  • param1 – x parameter name
  • param2 – y parameter name
  • param_pair – An [x,y] pair of params; can be set instead of param1 and param2
  • shaded – True if plot should be a shaded density plot (for the first samples plotted)
  • add_legend_proxy – True if should add to the legend proxy
  • line_offset – line_offset if not adding first contours to plot
  • proxy_root_exclude – any root names not to include when adding to the legend proxy
  • kwargs

    additional optional arguments:

    • filled: True for filled contours
    • lims: list of limits for the plot [xmin, xmax, ymin, ymax]
    • ls : list of line styles for the different sample contours plotted
    • colors: list of colors for the different sample contours plotted
    • lws: list of line widths for the different sample contours plotted
    • alphas: list of alphas for the different sample contours plotted
    • line_args: a list of dictionaries with settings for each set of contours
    • arguments for setAxes()
Returns:

The xbounds, ybounds of the plot.

from getdist import plots, gaussian_mixtures
samples1, samples2 = gaussian_mixtures.randomTestMCSamples(ndim=4, nMCSamples=2)
g = plots.getSinglePlotter(width_inch = 4)
g.plot_2d([samples1,samples2], 'x1', 'x2', filled=True);
_images/plots-5.png
plot_2d_scatter(roots, param1, param2, color='k', line_offset=0, add_legend_proxy=True, **kwargs)[source]

Make a 2D sample scatter plot.

If roots is a list of more than one, additional densities are plotted as contour lines.

Parameters:
  • roots – root name or MCSamples instance (or list of any of either of these) for the samples to plot
  • param1 – name of x parameter
  • param2 – name of y parameter
  • color – color to plot the samples
  • line_offset – The line index offset for added contours
  • add_legend_proxy – True if should add a legend proxy
  • kwargs

    additional optional arguments:

    • filled: True for filled contours for second and later items in roots
    • lims: limits for the plot [xmin, xmax, ymin, ymax]
    • ls : list of line styles for the different sample contours plotted
    • colors: list of colors for the different sample contours plotted
    • lws: list of linewidths for the different sample contours plotted
    • alphas: list of alphas for the different sample contours plotted
    • line_args: a list of dict with settings for contours from each root
plot_3d(roots, params=None, params_for_plots=None, color_bar=True, line_offset=0, add_legend_proxy=True, **kwargs)[source]

Make a 2D scatter plot colored by the value of a third parameter (a 3D plot).

If roots is a list of more than one, additional densities are plotted as contour lines.

Parameters:
  • roots – root name or MCSamples instance (or list of any of either of these) for the samples to plot
  • params – list with the three parameter names to plot (x, y, color)
  • params_for_plots – list of parameter triplets to plot for each root plotted; more general alternative to params
  • color_bar – True if should include a color bar
  • line_offset – The line index offset for added contours
  • add_legend_proxy – True if should add a legend proxy
  • kwargs

    additional optional arguments:

    • filled: True for filled contours for second and later items in roots
    • lims: limits for the plot [xmin, xmax, ymin, ymax]
    • ls : list of line styles for the different sample contours plotted
    • colors: list of colors for the different sample contours plotted
    • lws: list of linewidths for the different sample contours plotted
    • alphas: list of alphas for the different sample contours plotted
    • line_args: a list of dict with settings for contours from each root
    • arguments for add_colorbar()
from getdist import plots, gaussian_mixtures
samples1, samples2 = gaussian_mixtures.randomTestMCSamples(ndim=3, nMCSamples=2)
g = plots.getSinglePlotter(width_inch=4)
g.plot_3d([samples1, samples2], ['x0','x1','x2']);
_images/plots-6.png
plots_1d(roots, params=None, legend_labels=None, legend_ncol=None, label_order=None, nx=None, paramList=None, roots_per_param=False, share_y=None, markers=None, xlims=None, param_renames={}, **kwargs)[source]

Make an array of 1D marginalized density subplots

Parameters:
  • roots – root name or MCSamples instance (or list of any of either of these) for the samples to plot
  • params – list of names of parameters to plot
  • legend_labels – list of legend labels
  • legend_ncol – Number of columns for the legend.
  • label_order – minus one to show legends in reverse order that lines were added, or a list giving specific order of line indices
  • nx – number of subplots per row
  • paramList – name of .paramnames file listing specific subset of parameters to plot
  • roots_per_param – True to use a different set of samples for each parameter: plots param[i] using roots[i] (where roots[i] is the list of sample root names to use for plotting parameter i). This is useful for example for plotting one-parameter extensions of a baseline model, each with various data combinations.
  • share_y – True for subplots to share a common y axis with no horizontal space between subplots
  • markers – optional dict giving vertical markers index by parameter, or a list of marker values for each parameter plotted
  • xlims – list of [min,max] limits for the range of each parameter plot
  • param_renames – optional dictionary holding mapping between input names and equivalent names used in the samples.
  • kwargs – optional keyword arguments for plot_1d()
Returns:

The plot_col, plot_row subplot dimensions of the new figure

from getdist import plots, gaussian_mixtures
samples1, samples2 = gaussian_mixtures.randomTestMCSamples(ndim=4, nMCSamples=2)
g = plots.getSubplotPlotter()
g.plots_1d([samples1, samples2], ['x0', 'x1', 'x2'], nx=3, share_y=True, legend_ncol =2,
             markers={'x1':0}, colors=['red', 'green'], ls=['--', '-.'])
_images/plots-7.png
plots_2d(roots, param1=None, params2=None, param_pairs=None, nx=None, legend_labels=None, legend_ncol=None, label_order=None, filled=False, shaded=False, **kwargs)[source]

Make an array of 2D line, filled or contour plots.

Parameters:
  • roots – root name or MCSamples instance (or list of either of these) for the samples to plot
  • param1 – x parameter to plot
  • params2 – list of y parameters to plot against x
  • param_pairs – list of [x,y] parameter pairs to plot; either specify param1, param2, or param_pairs
  • nx – number of subplots per row
  • legend_labels – The labels used for the legend.
  • legend_ncol – The amount of columns in the legend.
  • label_order – minus one to show legends in reverse order that lines were added, or a list giving specific order of line indices
  • filled – True to plot filled contours
  • shaded – True to shade by the density for the first root plotted
  • kwargs – optional keyword arguments for plot_2d()
Returns:

The plot_col, plot_row subplot dimensions of the new figure

from getdist import plots, gaussian_mixtures
samples1, samples2 = gaussian_mixtures.randomTestMCSamples(ndim=4, nMCSamples=2)
g = plots.getSubplotPlotter(subplot_size=4)
g.settings.legend_frac_subplot_margin = 0.05
g.plots_2d([samples1, samples2], param_pairs=[['x0', 'x1'], ['x1', 'x2']],
                        nx=2, legend_ncol=2, colors=['blue', 'red'])
_images/plots-8.png
plots_2d_triplets(root_params_triplets, nx=None, filled=False, x_lim=None)[source]

Creates an array of 2D plots, where each plot uses different samples, x and y parameters

Parameters:
  • root_params_triplets – a list of (root, x, y) giving sample root names, and x and y parameter names to plot in each subplot
  • nx – number of subplots per row
  • filled – True for filled contours
  • x_lim – limits for all the x axes.
Returns:

The plot_col, plot_row subplot dimensions of the new figure

plots_3d(roots, param_sets, nx=None, legend_labels=None, **kwargs)[source]

Create multiple 3D subplots

Parameters:
  • roots – root name or MCSamples instance (or list of any of either of these) for the samples to plot
  • param_sets – A list of triplets of parameter names to plot [(x,y, color), (x2,y2,color2)..]
  • nx – number of subplots per row
  • legend_labels – list of legend labels
  • kwargs – keyword arguments for plot_3d()
Returns:

The plot_col, plot_row subplot dimensions of the new figure

from getdist import plots, gaussian_mixtures
samples1, samples2 = gaussian_mixtures.randomTestMCSamples(ndim=5, nMCSamples=2)
g = plots.getSubplotPlotter(subplot_size=4)
g.plots_3d([samples1, samples2], [['x0', 'x1', 'x2'], ['x3', 'x4', 'x2']], nx=2);
_images/plots-9.png
plots_3d_z(roots, param_x, param_y, param_z=None, max_z=None, **kwargs)[source]

Make set of sample scatter subplots of param_x against param_y, each coloured by values of parameters in param_z (all if None). Any second or more samples in root are shown as contours

Parameters:
  • roots – root name or MCSamples instance (or list of any of either of these) for the samples to plot
  • param_x – x parameter name
  • param_y – y parameter name
  • param_z – list of parameter to names to color samples in each subplot (default: all)
  • max_z – The maximum number of z parameters we should use.
  • kwargs – keyword arguments for plot_3d()
Returns:

The plot_col, plot_row subplot dimensions of the new figure

rectangle_plot(xparams, yparams, yroots=None, roots=None, plot_roots=None, plot_texts=None, xmarkers=None, ymarkers=None, marker_args={}, param_limits={}, legend_labels=None, legend_ncol=None, label_order=None, **kwargs)[source]

Make a grid of 2D plots.

A rectangle plot shows all x parameters plotted againts all y parameters in a grid of subplots with no spacing.

Set roots to use the same set of roots for every plot in the rectangle, or set yroots (list of list of roots) to use different set of roots for each row of the plot; alternatively plot_roots allows you to specify explicitly (via list of list of list of roots) the set of roots for each individual subplot

Parameters:
  • xparams – list of parameters for the x axes
  • yparams – list of parameters for the y axes
  • yroots – (list of list of roots) allows use of different set of root names for each row of the plot; set either roots or yroots
  • roots – list of root names or MCSamples instances. Uses the same set of roots for every plot in the rectangle; set either roots or yroots.
  • plot_roots – Allows you to specify (via list of list of list of roots) the set of roots for each individual subplot
  • plot_texts – a 2D array (or list of lists) of a text label to put in each subplot (use a None entry to skip one)
  • xmarkers – list of markers for the x axis
  • ymarkers – list of markers for the y axis
  • marker_args – arguments for add_x_marker() and add_y_marker()
  • param_limits – a dictionary holding a mapping from parameter names to axis limits for that parameter
  • legend_labels – list of labels for the legend
  • legend_ncol – The number of columns for the legend
  • label_order – minus one to show legends in reverse order that lines were added, or a list giving specific order of line indices
  • kwargs – arguments for plot_2d().
Returns:

the 2D list of Axes created

from getdist import plots, gaussian_mixtures
samples1, samples2 = gaussian_mixtures.randomTestMCSamples(ndim=4, nMCSamples=2)
g = plots.getSubplotPlotter()
g.rectangle_plot(['x0','x1'], ['x2','x3'], roots = [samples1, samples2], filled=True)
_images/plots-10.png
rotate_yticklabels(ax=None, rotation=90)[source]

Rotates the y-tick labels by given rotation (degrees)

Parameters:
  • ax – the Axes instance to use, defaults to current axes.
  • rotation – How much to rotate in degrees.
setAxes(params=[], lims=None, do_xlabel=True, do_ylabel=True, no_label_no_numbers=False, pos=None, prune=None, color_label_in_axes=False, ax=None, **other_args)[source]

Set the axis labels and ticks, and various styles. Do not usually need to call this directly.

Parameters:
  • params – [x,y] list of the ParamInfo for the x and y parameters to use for labels
  • lims – optional [xmin, xmax, ymin, ymax] to fix specific limits for the axes
  • do_xlabel – True if should include label for x axis.
  • do_ylabel – True if should include label for y axis.
  • no_label_no_numbers – True to hide tick labels
  • pos – optional position of the axes [‘left’ | ‘bottom’ | ‘width’ | ‘height’]
  • prune – Parameter for MaxNLocator constructor, [‘lower’ | ‘upper’ | ‘both’ | None]
  • color_label_in_axes – If True, and params has at last three entries, puts text in the axis to label the third parameter
  • ax – the Axes instance to use, defaults to current axes.
  • other_args – Not used, just quietly ignore so that setAxes can be passed general kwargs
Returns:

an Axes instance

set_xlabel(param, ax=None)[source]

Sets the label for the x axis.

Parameters:
  • param – the ParamInfo for the x axis parameter
  • ax – the Axes instance to use, defaults to current axes.
set_ylabel(param, ax=None)[source]

Sets the label for the y axis.

Parameters:
  • param – the ParamInfo for the y axis parameter
  • ax – the Axes instance to use, defaults to current axes.
show_all_settings()[source]

Prints settings and library versions

triangle_plot(roots, params=None, legend_labels=None, plot_3d_with_param=None, filled=False, shaded=False, contour_args=None, contour_colors=None, contour_ls=None, contour_lws=None, line_args=None, label_order=None, legend_ncol=None, legend_loc=None, upper_roots=None, upper_kwargs={}, **kwargs)[source]

Make a trianglular array of 1D and 2D plots.

A triangle plot is an array of subplots with 1D plots along the diagonal, and 2D plots in the lower corner. The upper triangle can also be used by setting upper_roots.

Parameters:
  • roots – root name or MCSamples instance (or list of any of either of these) for the samples to plot
  • params – list of parameters to plot (default: all, can also use glob patterns to match groups of parameters)
  • legend_labels – list of legend labels
  • plot_3d_with_param – for the 2D plots, make sample scatter plot, with samples colored by this parameter name (to make a ‘3D’ plot)
  • filled – True for filled contours
  • shaded – plot shaded density for first root (cannot be used with filled)
  • contour_args – optional dict (or list of dict) with arguments for each 2D plot (e.g. specifying color, alpha,etc)
  • contour_colors – list of colors for plotting contours (for each root)
  • contour_ls – list of Line styles for contours (for each root)
  • contour_lws – list of Line widths for contours (for each root)
  • line_args – dict (or list of dict) with arguments for each 2D plot (e.g. specifying ls, lw, color, etc)
  • label_order – minus one to show legends in reverse order that lines were added, or a list giving specific order of line indices
  • legend_ncol – The number of columns for the legend
  • legend_loc – The location for the legend
  • upper_roots – set to fill the upper triangle with subplots using this list of sample root names (TODO: this needs some work to easily work without a lot of tweaking)
  • upper_kwargs – list of dict for arguments when making upper-triangle 2D plots
  • kwargs – optional keyword arguments for plot_2d() or plot_3d() (lower triangle only)
from getdist import plots, gaussian_mixtures
samples1, samples2 = gaussian_mixtures.randomTestMCSamples(ndim=4, nMCSamples=2)
g = plots.getSubplotPlotter()
g.triangle_plot([samples1, samples2], filled=True, legend_labels = ['Contour 1', 'Contour 2'])
_images/plots-11.png
from getdist import plots, gaussian_mixtures
samples1, samples2 = gaussian_mixtures.randomTestMCSamples(ndim=4, nMCSamples=2)
g = plots.getSubplotPlotter()
g.triangle_plot([samples1, samples2], ['x0','x1','x2'], plot_3d_with_param='x3')
_images/plots-12.png
class getdist.plots.MCSampleAnalysis(chain_locations, settings=None)[source]

A class that loads and analyses samples, mapping root names to MCSamples objects with caching. Typically accessed as the instance stored in plotter.sampleAnalyser, for example to get an MCSamples instance from a root name being used by a plotter, use plotter.sampleAnalyser.samplesForRoot(name).

Parameters:
  • chain_locations – either a directory or the path of a grid of runs; it can also be a list of such, which is searched in order
  • settings – Either an IniFile instance, the name of an .ini file, or a dict holding sample analysis settings.
addChainDir(chain_dir)[source]

Adds a new chain directory or grid path for searching for samples

Parameters:chain_dir – The directory to add
addRoot(file_root)[source]

Add a root file for some new samples

Parameters:file_root – Either a file root name including path or a RootInfo instance
Returns:MCSamples instance for given root file.
addRoots(roots)[source]

A wrapper for addRoot that adds multiple file roots

Parameters:roots – An iterable containing filenames or RootInfo objects to add
boundsForRoot(root)[source]

Returns an object with getUpper and getLower to get hard prior bounds for given root name

Parameters:root – The root name to use.
Returns:object with getUpper() and getLower() functions
get_density(root, param, likes=False)[source]

Get Density1D for given root name and parameter

Parameters:
  • root – The root name of the samples to use
  • param – name of the parameter
  • likes – whether to include mean likelihood in density.likes
Returns:

Density1D instance with 1D marginalized density

get_density_grid(root, param1, param2, conts=2, likes=False)[source]

Get 2D marginalized density for given root name and parameters

Parameters:
  • root – The root name for samples to use.
  • param1 – x parameter
  • param2 – y parameter
  • conts – number of contour levels (up to maximum calculated using contours in analysis settings)
  • likes – whether to include mean likelihoods
Returns:

Density2D instance with marginalized density

load_single_samples(root)[source]

Gets a set of unit weight samples for given root name, e.g. for making sample scatter plot

Parameters:root – The root name to use.
Returns:array of unit weight samples
paramsForRoot(root, labelParams=None)[source]

Returns a ParamNames with names and labels for parameters used by samples with a given root name.

Parameters:
  • root – The root name of the samples to use.
  • labelParams – optional name of .paramnames file containing labels to use for plots, overriding default
Returns:

ParamNames instance

removeRoot(file_root)[source]

Remove a given root file (does not delete it)

Parameters:file_root – The file root to remove
reset(settings=None)[source]

Resets the caches, starting afresh optionally with new analysis settings

Parameters:settings – Either an IniFile instance, the name of an .ini file, or a dict holding sample analysis settings.
samplesForRoot(root, file_root=None, cache=True)[source]

Gets MCSamples from root name (or just return root if it is already an MCSamples instance).

Parameters:
  • root – The root name (without path, e.g. my_chains)
  • file_root – optional full root path, by default searches in self.chain_dirs
  • cache – if True, return cached object if already loaded
Returns:

MCSamples for the given root name

class getdist.plots.RootInfo(root, path, batch=None)[source]

Class to hold information about a set of samples loaded from file

Parameters:
  • root – The root file to use.
  • path – The path the root file is in.
  • batch – optional batch object if loaded from a grid of results
getdist.plots.getPlotter(**kwargs)[source]

Creates a new plotter and returns it

Parameters:kwargs – arguments for GetDistPlotter
Returns:The GetDistPlotter instance
getdist.plots.getSinglePlotter(ratio=0.75, width_inch=6, **kwargs)[source]

Get a GetDistPlotter for making a single plot of fixed width.

For a half-column plot for a paper use width_inch=3.464.

Use this or getSubplotPlotter() to make a GetDistPlotter instance for making plots. If you want customized sizes or styles for all plots, you can make a new module defining these functions, and then use it exactly as a replacement for getdist.plots.

Parameters:
  • ratio – The ratio between height and width.
  • width_inch – The width of the plot in inches
  • kwargs – arguments for GetDistPlotter
Returns:

The GetDistPlotter instance

getdist.plots.getSubplotPlotter(subplot_size=2, width_inch=None, **kwargs)[source]

Get a GetDistPlotter for making an array of subplots.

If width_inch is None, just makes plot as big as needed for given subplot_size, otherwise fixes total width and sets default font sizes etc. from matplotlib’s default rcParams.

Use this or getSinglePlotter() to make a GetDistPlotter instance for making plots. If you want customized sizes or styles for all plots, you can make a new module defining these functions, and then use it exactly as a replacement for getdist.plots.

Parameters:
  • subplot_size – The size of each subplot in inches
  • width_inch – Optional total width in inches
  • kwargs – arguments for GetDistPlotter
Returns:

The GetDistPlotter instance