GWForge.plotting¶
Corner plots and figure style for GWForge.
Attributes¶
Functions¶
|
Publication ready plot. |
|
Discrete colour cycle and continuous colormap for a named palette. |
|
LaTeX labels for parameter names, falling back to the escaped raw name. |
|
Density values enclosing the requested fractions of the total probability. |
|
Corner plot: 1-D marginals on the diagonal, 2-D contours below it. |
Module Contents¶
- 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.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 aboutGWForge.utilsrestyling 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).coloursis a tuple of hex strings to cycle through for overlaid datasets;colormapis amatplotlib.colors.LinearSegmentedColormapforcorner_plot()’scolour_byscatter.- 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.contourrequires.- 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
figto overlay a second. Pass the samespanto 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.
Nonemeans yes, unlesscolour_byis 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_byscatter.show_titles (bool) – Quantile titles over the diagonal panels. Pass
Falseon 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.
0disables it.
- Return type:
matplotlib.figure.Figure
- Raises:
ValueError – If
samplesis not two-dimensional, or iflabels,truths,spanorcolour_bydo not match its shape, or iffighas a different number of panels.