GWForge.plotting

Corner plots and figure style for GWForge.

Attributes

Functions

new_rcParams([width, aspect_ratio])

Publication ready plot.

palette([name])

Discrete colour cycle and continuous colormap for a named palette.

labels_for(parameters)

LaTeX labels for parameter names, falling back to the escaped raw name.

enclosed_levels(density, levels)

Density values enclosing the requested fractions of the total probability.

corner_plot(samples[, labels, weights, levels, span, ...])

Corner plot: 1-D marginals on the diagonal, 2-D contours below it.

Module Contents

GWForge.plotting.PHI = 1.618033988749895[source]
GWForge.plotting.TEALROSE = ('#009392', '#72aaa1', '#b1c7b3', '#f1eac8', '#e5b9ad', '#d98994', '#d0587e')[source]
GWForge.plotting.OKABE_ITO = ('#e69f00', '#56b4e9', '#009e73', '#f0e442', '#0072b2', '#d55e00', '#cc79a7', '#000000')[source]
GWForge.plotting.DEFAULT_PALETTE = 'tealrose'[source]
GWForge.plotting.XG_COLOUR = '#009392'[source]
GWForge.plotting.LVK_COLOUR = '#d0587e'[source]
GWForge.plotting.TRUTH_COLOUR = '0.2'[source]
GWForge.plotting.DEFAULT_LEVELS = (0.5, 0.9)[source]
GWForge.plotting.DEFAULT_QUANTILES = (0.16, 0.5, 0.84)[source]
GWForge.plotting.DEFAULT_SPAN_SIGMA = 4.0[source]
GWForge.plotting.HISTOGRAM_BINS = 60[source]
GWForge.plotting.SMOOTHING_BINS = 1.0[source]
GWForge.plotting.POPULATION_LATEX_LABELS[source]
GWForge.plotting.new_rcParams(width='column', aspect_ratio=PHI)[source]

Publication ready plot.

Parameters:
  • width (str) – "column" (246 pt) or "page" (510 pt), each doubled so the saved figure has room for readable fonts when scaled down.

  • aspect_ratio (float) – Width divided by height. Defaults to the golden ratio.

Returns:

Suitable for matplotlib.rc_context – which is how it should be used; see the note in the module docstring about GWForge.utils restyling matplotlib on import.

Return type:

dict

GWForge.plotting.palette(name=DEFAULT_PALETTE)[source]

Discrete colour cycle and continuous colormap for a named palette.

Parameters:

name (str) – "tealrose" or "okabe-ito".

Returns:

(colours, colormap). colours is a tuple of hex strings to cycle through for overlaid datasets; colormap is a matplotlib.colors.LinearSegmentedColormap for corner_plot()’s colour_by scatter.

Return type:

tuple

Raises:

ValueError – For an unknown palette name.

GWForge.plotting.labels_for(parameters)[source]

LaTeX labels for parameter names, falling back to the escaped raw name.

The fallback escapes underscores so mathtext does not read them as subscripts and silently mangle the label.

Parameters:

parameters (sequence of str)

Return type:

list of str

GWForge.plotting.enclosed_levels(density, levels)[source]

Density values enclosing the requested fractions of the total probability.

Sort the histogram, walk down the cumulative sum, and read off where each fraction is reached. This is what makes a “90% contour” contain 90% of the samples rather than trace an arbitrary isopleth of the density.

Parameters:
  • density (numpy.ndarray) – Histogram or smoothed density, any shape.

  • levels (sequence of float) – Enclosed probabilities in (0, 1).

Returns:

Contour values, sorted ascending as matplotlib.contour requires.

Return type:

numpy.ndarray

GWForge.plotting.corner_plot(samples, labels=None, weights=None, levels=DEFAULT_LEVELS, span=None, quantiles=DEFAULT_QUANTILES, truths=None, colour=None, alpha=0.5, linewidth=1.5, fill=None, colour_by=None, colour_label=None, palette_name=DEFAULT_PALETTE, scatter_size=2.0, show_titles=True, title_fmt='.3f', label=None, fig=None, size=None, bins=HISTOGRAM_BINS, smooth=SMOOTHING_BINS)[source]

Corner plot: 1-D marginals on the diagonal, 2-D contours below it.

Call once per dataset, passing the returned figure back as fig to overlay a second. Pass the same span to both so the panels line up – ranges are computed per call otherwise.

Parameters:
  • samples (array_like) – (n_samples, n_dimensions).

  • labels (sequence of str or None) – Axis labels, already LaTeX. See labels_for().

  • weights (array_like or None) – Per-sample weights.

  • levels (sequence of float) – Enclosed probabilities, not density values. See enclosed_levels().

  • span (sequence of tuple or None) – (low, high) per dimension. Defaults to mean +/- 4 sample standard deviations.

  • quantiles (sequence of float) – Three quantiles for the diagonal titles: lower, central, upper.

  • truths (array_like or None) – Reference values, drawn as lines.

  • colour (str or None) – Contour colour. Defaults to the first entry of palette_name.

  • alpha (float) – Fill opacity. The outline is always drawn at full opacity so overlaid contours stay legible.

  • linewidth (float)

  • fill (bool or None) – Fill the contours as well as outlining them. None means yes, unless colour_by is given – a filled contour drawn over a scatter hides exactly the points the scatter exists to show.

  • colour_by (array_like or None) – Length n_samples. When given, each lower-triangle panel scatters the samples coloured by this on the palette’s continuous map, with one shared colourbar. This is the pycbc posterior idiom – events coloured by redshift or by network SNR.

  • colour_label (str or None) – Colourbar label.

  • palette_name (str) – "tealrose" or "okabe-ito".

  • scatter_size (float) – Marker size for the colour_by scatter.

  • show_titles (bool) – Quantile titles over the diagonal panels. Pass False on overlays so the first dataset’s titles are not overwritten.

  • title_fmt (str)

  • label (str or None) – Legend entry for this dataset.

  • fig (matplotlib.figure.Figure or None) – Existing corner to draw onto.

  • size (tuple or None) – Figure size in inches. Defaults to (3 n, 3 n).

  • bins (int) – Histogram bins per axis.

  • smooth (float) – Gaussian smoothing in units of bins. 0 disables it.

Return type:

matplotlib.figure.Figure

Raises:

ValueError – If samples is not two-dimensional, or if labels, truths, span or colour_by do not match its shape, or if fig has a different number of panels.