Skip to content

virgil.plotting

Plotting functions for virgil models, data and grid results.

units="flux" | "contrast" | "delta_mag" shows contrasts as companion/primary flux, primary/companion, or magnitudes. Sky images have East (positive dra) to the left and North up. Importing this module leaves matplotlib's global settings alone; set_style opts in to the virgil look.

set_style()

Apply the virgil matplotlib style globally.

The plotting functions in this module already use this style for the figures they create, without touching global settings. Call this to use it for your own figures too.

plot_grid_map(values, grid, kind='loglike', *, units='flux', sigma=None, percentile=None, truth=None, best=None, star=True, flux_param=None, ax=None, cmap=None, log=None, label=None, title=None, figsize=(7, 6))

Plot a grid result as a sky map (or a 1D profile).

Parameters:

Name Type Description Default
values array - like

Grid result with one axis per coordinate key of grid (every key but the flux), from virgil.grid_fit or virgil.limits; a full likelihood_grid is reduced to its maximum over flux. One coordinate gives a line plot.

required
grid dict[str, array - like]

The grid axes used to compute values.

required
kind (loglike, flux, sigma, snr, limit)

What values holds; sets the default colour map, scale and labels.

"loglike"
units (flux, contrast, delta_mag)

For kind="flux" and "limit": flux ratios, contrasts or magnitude differences.

"flux"
sigma float

Confidence of a kind="limit" map, for its title.

None
percentile float

Confidence of a kind="limit" map, for its title.

None
truth dict or sequence

Coordinates to mark with a cross (truth) or circle (best fit).

None
best dict or sequence

Coordinates to mark with a cross (truth) or circle (best fit).

None
star bool

Mark the primary at the origin of sky maps (default True).

True
flux_param str

Key of the flux axis, if it is not the one key ending in flux.

None
ax optional

Axes to draw on (default: a new figure of this size).

None
figsize optional

Axes to draw on (default: a new figure of this size).

None
cmap optional

Override the defaults for kind.

None
log optional

Override the defaults for kind.

None
label optional

Override the defaults for kind.

None
title optional

Override the defaults for kind.

None

Returns:

Type Description
tuple

(fig, ax); dra is x and ddec y whatever their order in grid.

Examples:

>>> plot_grid_map(limits, grid, kind="limit", units="delta_mag", sigma=5)

plot_contrast_curve(values, grid=None, *, units='delta_mag', sigma=None, percentile=None, label=None, band=True, truth=None, center=(0.0, 0.0), r_max=None, bins=20, ax=None, color=None, figsize=(8, 4))

Plot a radial contrast curve: the median limit against separation.

Parameters:

Name Type Description Default
values array - like or dict

A limit map (companion/primary flux ratios, one axis per coordinate key of grid, as from absil_limits or ruffio_upperlimit), or a radial_profile of one.

required
grid dict[str, array - like]

The grid axes of a limit map; must contain dra and ddec.

None
units (delta_mag, contrast, flux)

Magnitude differences (default), contrasts or flux ratios. Deeper limits are always drawn lower down.

"delta_mag"
sigma optional

Legend label; by default built from sigma or percentile.

None
percentile optional

Legend label; by default built from sigma or percentile.

None
label optional

Legend label; by default built from sigma or percentile.

None
band bool

Shade the 16-84 percentile range of each annulus (default True).

True
truth tuple

(dra, ddec, flux) of a detected companion to mark.

None
center optional

Annuli, passed to radial_profile.

(0.0, 0.0)
r_max optional

Annuli, passed to radial_profile.

(0.0, 0.0)
bins optional

Annuli, passed to radial_profile.

(0.0, 0.0)
ax optional

Axes to draw on, e.g. to overlay several curves (default: a new figure of this size).

None
figsize optional

Axes to draw on, e.g. to overlay several curves (default: a new figure of this size).

None
color optional

Line and band colour.

None

Returns:

Type Description
tuple

(fig, ax).

plot_null_distribution(mc, stat='delta_chi2', *, observed=None, fap=None, reference=True, ax=None, title=None, figsize=(7, 4.5))

Plot how often companion-free searches exceed each threshold.

The empirical exceedance function of the statistic over the null simulations, on a log scale. See detection limits.

Parameters:

Name Type Description Default
mc DetectionMC

Simulated searches, from injection_recovery.

required
stat str

"delta_chi2" (default), "log_bayes_factor" or "max_snr".

'delta_chi2'
observed float

The statistic of the real data: a vertical line, with its false-alarm probability and 95% interval.

None
fap float

A false-alarm probability to draw as a horizontal line, with the threshold that reaches it.

None
reference bool

Draw the single-position reference curve (default True; none for log_bayes_factor).

True
title optional

Title (default: statistic and number of draws), axes, and size of a new figure.

None
ax optional

Title (default: statistic and number of draws), axes, and size of a new figure.

None
figsize optional

Title (default: statistic and number of draws), axes, and size of a new figure.

None

Returns:

Type Description
tuple

(fig, ax).

Examples:

>>> plot_null_distribution(mc, "delta_chi2", observed=21.3)

plot_roc(mc, stat, *, flux=None, sep_bin=None, ax=None, log_fpr=True, mark_wilks=(3.0, 5.0), title=None, figsize=(7, 4.5))

Plot ROC curves: completeness against false-alarm probability.

A useless statistic lies on TPR = FPR; see detection limits.

Parameters:

Name Type Description Default
mc DetectionMC

Simulated searches, from injection_recovery.

required
stat str or sequence of str

"delta_chi2", "log_bayes_factor" or "max_snr", or several.

required
flux (float, (float, float) or list)

Only injections of this flux or in this range, as for DetectionMC.roc; a list gives one curve per entry.

None
sep_bin (float, float) or list of them

Only injections with separation in [lo, hi) (mas); a list gives one curve per bin.

None
log_fpr bool

Logarithmic false-positive axis.

True
mark_wilks sequence of float

Local significances at which to mark the single-position false-alarm probability and its threshold on each curve (the gap is the look-elsewhere effect); () marks nothing.

(3.0, 5.0)
title optional

Title (default: what the curves share), axes, and size of a new figure.

None
ax optional

Title (default: what the curves share), axes, and size of a new figure.

None
figsize optional

Title (default: what the curves share), axes, and size of a new figure.

None

Returns:

Type Description
tuple

(fig, ax).

Examples:

>>> plot_roc(mc, ["delta_chi2", "max_snr"], flux=4e-3)

plot_completeness(mc, stat, fap, *, units='delta_mag', contours=(0.5, 0.9), sep_bins=None, flux_bins=None, ax=None, cmap='viridis', colorbar=True, title=None, figsize=(8, 4.5))

Plot a completeness map against separation and companion brightness.

Each cell is the fraction of injections detected at false-alarm probability fap (DetectionMC.completeness); lines mark contours. See detection limits.

Parameters:

Name Type Description Default
mc DetectionMC

Simulated searches with injections, from injection_recovery.

required
stat str

The detection statistic, e.g. "delta_chi2".

required
fap float

False-alarm probability of the threshold, e.g. 1.35e-3 (3σ).

required
units (delta_mag, contrast, flux)

The y-axis, as in plot_contrast_curve (delta_mag is 2.5 log10(primary/companion)).

"delta_mag"
contours sequence of float

Completeness levels to draw as lines (default 50% and 90%).

(0.5, 0.9)
sep_bins array - like

Bin edges (mas, and flux); by default every injected value is a cell.

None
flux_bins array - like

Bin edges (mas, and flux); by default every injected value is a cell.

None
cmap str or Colormap

Colour map of the completeness, from 0 to 1.

'viridis'
colorbar bool

Add a colour bar.

True
title optional

Title (default: statistic and FAP), axes, and size of a new figure.

None
ax optional

Title (default: statistic and FAP), axes, and size of a new figure.

None
figsize optional

Title (default: statistic and FAP), axes, and size of a new figure.

None

Returns:

Type Description
tuple

(fig, ax).

Examples:

>>> plot_completeness(mc, "delta_chi2", 1.35e-3)

plot_orbit_ensemble(orbits, positions=None, truth=None, *, n_points=400, n_sigma=1.0, color='#3c6e9f', alpha=None, truth_color='#d1495b', cmap='viridis', ax=None, figsize=(6.5, 6))

Draw orbits on the sky, e.g. draws from a posterior, with the data.

East is to the left and North up, the primary at the origin. Each orbit is drawn over one period; measured positions are coloured by time, with error ellipses.

Parameters:

Name Type Description Default
orbits KeplerOrbit

One orbit, or many as one KeplerOrbit whose elements are 1-D arrays of equal length.

required
positions PositionData

Measured positions to overlay, with n_sigma error ellipses.

None
truth KeplerOrbit

A reference orbit, drawn as a thicker contrasting line.

None
n_points int

Points along each orbit.

400
n_sigma float

Size of the error ellipses, in standard deviations.

1.0
color optional

Colours of the ensemble and of the reference orbit.

'#3c6e9f'
truth_color optional

Colours of the ensemble and of the reference orbit.

'#3c6e9f'
alpha float

Opacity of each line; by default it falls with the number of orbits.

None
cmap str

Colour map for the epochs' times.

'viridis'
ax Axes

Axes to draw on.

None
figsize tuple

Size of a new figure.

(6.5, 6)

Returns:

Type Description
tuple

(fig, ax).

plot_field_draws(field=None, pixel_scale_mas=None, key=None, *, latents=None, images=None, n=100, cuts=None, axes_pa=((0.0, 'vertical'), (90.0, 'horizontal')), mmax=3, npix=64, truth=None, snr=False, beam=None, snr_scale='linear', snr_vmax=None, n_cuts=100, title=None, figsize=(9, 6))

Draws from a Gaussian-process image prior or posterior, with cuts.

Provisional

May change in any 0.4.x release without a deprecation cycle.

Three draws (abc) above cuts through many (ddd), one in bold. Posterior draws are unit-sum on a shared colour scale; prior draws have unit peak.

Parameters:

Name Type Description Default
field (GaussianField, MultipoleField or MultipoleDisk)

Alone, prior draws from key; with latents, posterior draws. A MultipoleDisk needs a RadialGP profile; latents are drawn at its hyperparameters.

None
pixel_scale_mas float

Pixel scale, mas.

None
key Array

PRNG key (prior).

None
latents (array - like, shape(n, *shape) or dict)

Posterior latents, e.g. from laplace_samples. For a MultipoleDisk, a dict of disk paths, {"profile.z": ..., "harmonics.z": ...}, each (n, *shape); others keep their values.

None
images (array - like, shape(n, nrow, ncol))

Rendered images instead of a field (not for "multipole" cuts).

None
n int

Prior draws (default 100).

100
cuts (principal, axes, multipole)

Panel d. "principal": central row and column of a GaussianField. "axes": lines through the centre at axes_pa. "multipole": cosine amplitudes a_m(r) of η = Σ a_m cos mθ + b_m sin mθ (the residual without mean; a_0 is the azimuthal mean), one offset track per m = 0..mmax; for a MultipoleDisk, ln I₀ - μ and the coefficients c_m(r) of I/I₀. Default: "multipole" for a MultipoleField or disk, "principal" for a GaussianField, "axes" for images.

"principal"
axes_pa sequence of (float, str)

(PA in degrees, label), North through East, per "axes" cut.

((0.0, 'vertical'), (90.0, 'horizontal'))
npix int

Image side in pixels for a disk (default 64).

64
truth (array - like, shape(nrow, ncol))

True image (posterior only): dashed in the cuts; the reference peak.

None
snr bool

Posterior only. Panel c: mean over standard deviation of each pixel (grey where no spread); per-pixel S/N, not a detection significance.

False
beam Beam

Drawn on the map panels, as in plot_model.

None
snr_scale optional

S/N scale ("linear"/"log"), its top (default 99th percentile), faint cuts (100), title, size.

'linear'
snr_vmax optional

S/N scale ("linear"/"log"), its top (default 99th percentile), faint cuts (100), title, size.

'linear'
n_cuts optional

S/N scale ("linear"/"log"), its top (default 99th percentile), faint cuts (100), title, size.

'linear'
title optional

S/N scale ("linear"/"log"), its top (default 99th percentile), faint cuts (100), title, size.

'linear'
figsize optional

S/N scale ("linear"/"log"), its top (default 99th percentile), faint cuts (100), title, size.

'linear'

Returns:

Type Description
tuple

(fig, axes), axes a dict keyed "a" to "d". Prior cuts show η; others log10 brightness over the reference peak.

plot_model(model, fov_mas, npix=256, ax=None, title=None, saturate=None, cmap='magma', beam=None, convolve=False)

Show a source model's rendered image with sky axes (East left, North up).

Parameters:

Name Type Description Default
model SourceModel

Model to render.

required
fov_mas float

Width of the field of view in milliarcseconds.

required
npix int

Number of pixels on a side.

256
ax Axes

Axes to draw on; a new figure is made if omitted.

None
title str

Axes title.

None
saturate float

Quantile (e.g. 0.99) at which to saturate the colour scale.

None
cmap str

Matplotlib colour map.

'magma'
beam Beam

The data's resolution, from imaging.beam, drawn as a shaded FWHM ellipse in the lower-left corner.

None
convolve bool

Show the image convolved with beam (see imaging.convolve_beam).

False

Returns:

Type Description
Axes

The axes drawn on.

plot_residual_map(residual, fov_mas, sigma=None, ax=None, title=None, cmap='RdBu_r')

Show a signed residual image on a symmetric, diverging colour scale.

Use it next to an image and its reconstruction (or data and a model) to see where they agree. Without sigma the map is the plain signed residual, as for a maximum a posteriori image with no uncertainty. With sigma it is the z-score residual / sigma. The colour scale is centred on zero in either case, with East to the left and North up.

Parameters:

Name Type Description Default
residual (array - like, shape(npix, npix))

E.g. reconstruction.render(npix, fov) - truth.render(npix, fov), in the orientation of render.

required
fov_mas float

Width of the field of view in milliarcseconds.

required
sigma array - like or float

Uncertainty of the residual, per pixel or overall; if given, the map shows z-scores.

None
ax Axes

Axes to draw on; a new figure is made if omitted.

None
title str

Axes title.

None
cmap str

A diverging Matplotlib colour map.

'RdBu_r'

Returns:

Type Description
Axes

The axes drawn on (with a colour bar).

plot_uv_coverage(data, ax=None, cmap='viridis', figsize=(6, 5.5))

Plot the uv coverage of data, coloured by wavelength.

Each sample is drawn at (u, v) and at its mirror (-u, -v) (the visibility there is the conjugate), in units of millions of wavelengths, with East (positive u) to the left as on the sky.

Parameters:

Name Type Description Default
data OIData

Data to show. Flagged samples are drawn too: the coverage is that of the observation.

required
ax Axes

Axes to draw on; a new figure is made if omitted.

None
cmap str

Colour map of the wavelength, used when the data have more than one wavelength (one colour otherwise).

'viridis'
figsize tuple

Size of a new figure.

(6, 5.5)

Returns:

Type Description
tuple

(fig, ax).

plot_oidata_overview(oidata, figsize=(15, 4.5))

Plot uv coverage, visibilities and phases of an OIData object.

Parameters:

Name Type Description Default
oidata OIData

Data to show. Flagged samples are left out. Projected observables (vis_mat/phi_mat) have no baseline and are not shown against it.

required
figsize tuple

Figure size.

(15, 4.5)

Returns:

Type Description
tuple

(fig, (ax_uv, ax_vis, ax_phi)).

plot_data_model_correlation(oidata, predictions_by_label, colors=None, figsize=(10, 5), phase_title='Phase correlation', square_axes=True, vis_label=None)

Plot data-vs-model correlation panels for visibility and phase observables.

Parameters:

Name Type Description Default
oidata OIData

Observed data container.

required
predictions_by_label dict

Mapping label -> prediction summary where each summary contains vis_mean, vis_std, phi_mean, phi_std arrays.

required
colors list

Matplotlib color list. If omitted, cycle C0, C1, ...

None
figsize tuple

Figure size.

(10, 5)
phase_title str

Title for the phase panel.

'Phase correlation'
square_axes bool

If True, enforce square panel boxes for both subplots.

True
vis_label str

Axis label for the visibility observable. By default it follows oidata.vis_mode: V² and amplitudes are shown in percent, log-amplitudes and projected (e.g. DISCO) observables as plain values.

None

Returns:

Type Description
tuple

(fig, (ax1, ax2)) for visibility and phase axes. Data with no phase observables (e.g. AMIGO DISCOs, which hold every observable in vis) leave the phase axis hidden and give the visibility panel the whole figure.

plot_chainconsumer_diagnostics(chains_by_label, columns, truth=None, colors=None, walk_columns=None)

Plot comparison diagnostics using ChainConsumer for multiple posterior chains.

Parameters:

Name Type Description Default
chains_by_label dict

Mapping label -> pandas.DataFrame containing chain samples.

required
columns list[str]

Columns used for contour/corner plotting.

required
truth dict

Truth mapping for columns displayed. When omitted, no truth overlay is drawn.

None
colors list[str]

Per-chain colors.

None
walk_columns list[str]

Columns to show in walk plots. Defaults to columns.

None

Returns:

Type Description
tuple

(consumer, corner_fig, walks_fig): the configured ChainConsumer instance and the two figures it drew.

diagnostics_table_from_samples(samples, dra_key='dra', ddec_key='ddec', flux_key='flux', log10_flux=False)

Build a standardized diagnostics table from posterior sample arrays.

Parameters:

Name Type Description Default
samples dict - like

Mapping of sample arrays.

required
dra_key str

Key for right-ascension offsets.

'dra'
ddec_key str

Key for declination offsets.

'ddec'
flux_key str

Key for flux or log10-flux samples.

'flux'
log10_flux bool

If True, exponentiate flux_key values as base-10.

False

Returns:

Type Description
DataFrame

Table with dra, ddec, flux, sep, and pa columns.

truth_cartesian_and_polar(truth)

Return truth mappings for shared ChainConsumer Cartesian and polar interfaces.

Parameters:

Name Type Description Default
truth dict

Mapping with dra, ddec, and flux values.

required

Returns:

Type Description
tuple[dict, dict]

Cartesian and polar truth dictionaries.