Plotting Module (brutus.plotting)¶
brutus.plotting generates diagnostic and publication figures from BruteForce posterior outputs and stellar model grids, including corner plots of intrinsic and extrinsic parameters, posterior predictive SED comparisons, 2D distance-reddening posteriors, and empirical photometric offset residuals.
Corner Plots¶
- brutus.plotting.cornerplot(idxs, data, params, lndistprior=None, coord=None, avlim=(0.0, 20.0), rvlim=(1.0, 8.0), weights=None, parallax=None, parallax_err=None, Nr=500, applied_parallax=None, pcolor='blue', parallax_kwargs=None, span=None, quantiles=[0.025, 0.5, 0.975], color='black', smooth=10, hist_kwargs=None, hist2d_kwargs=None, labels=None, label_kwargs=None, show_titles=False, title_fmt='.2f', title_kwargs=None, title_quantiles=[0.025, 0.5, 0.975], truths=None, truth_color='red', truth_kwargs=None, max_n_ticks=5, top_ticks=False, use_math_text=False, verbose=False, fig=None, rstate=None, R_solar=8.2, Z_solar=0.025)[source]¶
Generate a corner plot of the 1-D and 2-D marginalized posteriors.
- Parameters:
idxs (~numpy.ndarray of shape (Nsamps)) – An array of resampled indices corresponding to the set of models used to fit the data.
data (3-tuple or 4-tuple of ~numpy.ndarray of shape (Nsamps,)) – Either saved
(dists, reds, dreds)draws in(kpc, mag, -)or(scales, avs, rvs, covs_sar)used to regenerate draws under the distance and parallax priors. Saved draws are preferred because regeneration applies only the distance and parallax priors rather than the dust-map and label-dependent priors used during fitting.params (structured ~numpy.ndarray of shape (Nmodels,)) – Structured array of model parameters. The
'agewt'field is ignored.lndistprior (callable, optional) – Log-distance prior function. Default is
logp_galactic_structure().coord (2-tuple of float, optional) – Galactic
(l, b)coordinates in degrees passed tolndistprior.avlim (2-tuple of float, optional) – \(A(V)\) bounds in magnitudes used to truncate regenerated draws. Default is
AVLIM(0.0, 20.0).rvlim (2-tuple of float, optional) – \(R(V)\) bounds used to truncate regenerated draws. Default is
RVLIM(1.0, 8.0).weights (~numpy.ndarray of shape (Nsamps,), optional) – Importance weights for the samples.
parallax (float, optional) – Measured parallax for the source in milliarcseconds (mas).
parallax_err (float, optional) – Parallax uncertainty in milliarcseconds (mas).
Nr (int, optional) – The number of Monte Carlo realizations used when sampling using the provided parallax prior. Default is 500.
applied_parallax (bool or None, optional) – Whether to apply the parallax prior to the draws regenerated from (scales, avs, rvs, covs_sar). None applies it when both parallax and parallax_err are given. True without both raises ValueError. Saved (dists, reds, dreds) ignore it. Default is None.
pcolor (str, optional) – Color used when plotting the parallax prior. Default is ‘blue’.
parallax_kwargs (kwargs, optional) – Keyword arguments used when plotting the parallax prior passed to fill_between.
span (iterable with shape (ndim,), optional) –
A list where each element is either a length-2 tuple containing lower and upper bounds or a float from (0., 1.] giving the fraction of (weighted) samples to include. If a fraction is provided, the bounds are chosen to be equal-tailed. An example would be:
span = [(0., 10.), 0.95, (5., 6.)]
Default is 0.99 (99% credible interval).
quantiles (iterable, optional) – A list of fractional quantiles to overplot on the 1-D marginalized posteriors as vertical dashed lines. Default is [0.025, 0.5, 0.975] (spanning the 95%/2-sigma credible interval).
color (str or iterable with shape (ndim,), optional) – A ~matplotlib-style color (either a single color or a different value for each subplot) used when plotting the histograms. Default is ‘black’.
smooth (float or iterable with shape (ndim,), optional) – The standard deviation (either a single value or a different value for each subplot) for the Gaussian kernel used to smooth the 1-D and 2-D marginalized posteriors, expressed as a fraction of the span. If an integer is provided instead, this will instead default to a simple (weighted) histogram with bins=smooth. Default is 10 (10 bins).
hist_kwargs (dict, optional) – Extra keyword arguments to send to the 1-D (smoothed) histograms.
hist2d_kwargs (dict, optional) – Extra keyword arguments to send to the 2-D (smoothed) histograms.
labels (iterable with shape (ndim,), optional) – The field names of params to plot, which are also the axis text. A name that is not a field of params raises ValueError. If not provided, all fields of params except ‘agewt’ are plotted. The panels ‘Av’, ‘Rv’, ‘Parallax’ and ‘Distance’ follow.
label_kwargs (dict, optional) – Extra keyword arguments that will be sent to the ~matplotlib.axes.Axes.set_xlabel and ~matplotlib.axes.Axes.set_ylabel methods.
show_titles (bool, optional) – Whether to display a title above each 1-D marginalized posterior showing the quantiles specified by title_quantiles. By default, This will show the median (0.5 quantile) along with the upper/lower bounds associated with the 0.025 and 0.975 (95%/2-sigma credible interval) quantiles. Default is False.
title_fmt (str, optional) – The format string for the quantiles provided in the title. Default is ‘.2f’.
title_kwargs (dict, optional) – Extra keyword arguments that will be sent to the ~matplotlib.axes.Axes.set_title command.
title_quantiles (iterable, optional) – A list of 3 fractional quantiles displayed in the title, ordered from lowest to highest. Default is [0.025, 0.5, 0.975] (spanning the 95%/2-sigma credible interval).
truths (iterable with shape (ndim,), optional) – A list of reference values that will be overplotted on the traces and marginalized 1-D posteriors as solid horizontal/vertical lines. Individual values can be exempt using None. Default is None.
truth_color (str or iterable with shape (ndim,), optional) – A ~matplotlib-style color (either a single color or a different value for each subplot) used when plotting truths. Default is ‘red’.
truth_kwargs (dict, optional) – Extra keyword arguments that will be used for plotting the vertical and horizontal lines with truths.
max_n_ticks (int, optional) – Maximum number of ticks allowed. Default is 5.
top_ticks (bool, optional) – Whether to label the top (rather than bottom) ticks. Default is False.
use_math_text (bool, optional) – Whether the axis tick labels for very large/small exponents should be displayed as powers of 10 rather than using e. Default is False.
verbose (bool, optional) – Whether to print the values of the computed quantiles associated with each parameter. Default is False.
fig ((~matplotlib.figure.Figure, ~numpy.ndarray), optional) – Existing figure and
(ndim, ndim)axes grid to overplot on. If None, a new figure is created.rstate (~numpy.random.RandomState or ~numpy.random.Generator, optional) – Random number generator for regenerating draws.
R_solar (float, optional) – Solar Galactocentric radius in kpc passed to the default distance prior. Default is 8.2.
Z_solar (float, optional) – Solar height above the Galactic midplane in kpc passed to the default distance prior. Default is 0.025.
- Returns:
cornerplot – Figure and
(ndim, ndim)axes array of the corner plot.- Return type:
(~matplotlib.figure.Figure, ~numpy.ndarray)
- Raises:
ValueError – If
datadoes not have 3 or 4 elements, ifapplied_parallax=Truewithout bothparallaxandparallax_err, ifweightsis not 1-D of lengthNsamps, or iffigaxes do not match(ndim, ndim).
SED Visualization¶
- brutus.plotting.posterior_predictive(models, idxs, reds, dreds, dists, weights=None, flux=False, data=None, data_err=None, data_mask=None, offset=None, vcolor='black', pcolor='black', labels=None, rstate=None, psig=2.0, fig=None)[source]¶
Plot the posterior predictive SED.
- Parameters:
models (~numpy.ndarray of shape (Nmodels, Nfilts, Ncoeffs)) – Array of magnitude polynomial coefficients used to generate reddened photometry.
idxs (~numpy.ndarray of shape (Nsamps)) – An array of resampled indices corresponding to the set of models used to fit the data.
reds (~numpy.ndarray of shape (Nsamps)) – Reddening samples (in Av) associated with the model indices.
dreds (~numpy.ndarray of shape (Nsamps)) – “Differential” reddening samples (in Rv) associated with the model indices.
dists (~numpy.ndarray of shape (Nsamps)) – Distance samples (in kpc) associated with the model indices.
weights (~numpy.ndarray of shape (Nsamps), optional) – An optional set of importance weights used to reweight the samples.
flux (bool, optional) – Whether to plot SEDs in linear flux densities (maggies) rather than magnitudes. Default is False.
data (~numpy.ndarray of shape (Nfilt,), optional) – Observed flux densities in maggies to overplot.
data_err (~numpy.ndarray of shape (Nfilt,), optional) – Observed 1-sigma flux density uncertainties in maggies, overplotted as
psig-sigma error bars.data_mask (~numpy.ndarray of shape (Nfilt,), optional) – Boolean mask (or 0/1 values) indicating observed bands.
offset (~numpy.ndarray of shape (Nfilt,), optional) – Multiplicative photometric flux offsets applied to
dataanddata_err.vcolor (str, optional) – Color for the posterior predictive violin plots. Default is
'black'.pcolor (str, optional) – Color for the observed photometric points. Default is
'black'.labels (sequence of str of length Nfilt, optional) – Filter names for the x-axis tick labels. If not provided, integer indices
(0, 1, ..., Nfilt - 1)are used.rstate (~numpy.random.RandomState or ~numpy.random.Generator, optional) – Random number generator used to resample weighted draws.
psig (float, optional) – Error-bar multiple applied to
data_err. Default is2.0.fig ((~matplotlib.figure.Figure, ~matplotlib.axes.Axes), optional) – If provided, draw on the given axes and leave the figure layout unchanged. Otherwise, a new figure is created and laid out with ~matplotlib.figure.Figure.tight_layout.
- Returns:
postpredplot – Figure, axes, and violinplot artist dictionary.
- Return type:
(~matplotlib.figure.Figure, ~matplotlib.axes.Axes, dict)
- Raises:
ValueError – If
weightsis not 1-D of lengthNsampsordata_maskdoes not have shape(Nfilt,).
Summary Plots¶
- brutus.plotting.summary_plot(models, idxs, reds, dreds, dists, params, data=None, data_err=None, data_mask=None, offset=None, coord=None, parallax=None, parallax_err=None, labels=None, weights=None, show_titles=True, color='black', vcolor='black', pcolor='black', R_solar=8.2, Z_solar=0.025, figsize=None, rstate=None, **corner_kwargs)[source]¶
Generate a combined corner plot with posterior predictive SED inset.
Creates a corner plot of the stellar parameter posteriors with the posterior predictive SED placed in the upper-right triangle, making efficient use of the figure space.
- Parameters:
models (~numpy.ndarray of shape (Nmodels, Nfilts, Ncoeffs)) – Model magnitude polynomial coefficients.
idxs (~numpy.ndarray of shape (Nsamps)) – Resampled model indices.
reds (~numpy.ndarray of shape (Nsamps,)) – Extinction \(A(V)\) samples in magnitudes.
dreds (~numpy.ndarray of shape (Nsamps,)) – Reddening curve slope \(R(V)\) samples.
dists (~numpy.ndarray of shape (Nsamps,)) – Distance samples in kpc.
params (structured ~numpy.ndarray of shape (Nmodels,)) – Structured array of model parameters for the corner plot axes.
data (~numpy.ndarray of shape (Nfilt,), optional) – Observed flux densities in maggies for the posterior predictive SED.
data_err (~numpy.ndarray of shape (Nfilt,), optional) – Observed 1-sigma flux density uncertainties in maggies.
data_mask (~numpy.ndarray of shape (Nfilt,), optional) – Boolean mask (or 0/1 values) indicating valid bands.
offset (~numpy.ndarray of shape (Nfilt,), optional) – Multiplicative photometric flux offsets.
coord (2-tuple of float, optional) – Galactic
(l, b)coordinates in degrees.parallax (float, optional) – Measured parallax in milliarcseconds (mas).
parallax_err (float, optional) – Parallax uncertainty in milliarcseconds (mas).
labels (sequence of str of length Nfilt, optional) – Filter names for the SED x-axis.
weights (~numpy.ndarray of shape (Nsamps,), optional) – Importance weights for the samples.
show_titles (bool, optional) – Whether to show parameter titles on the corner plot.
color (str, optional) – Color for the corner plot. Default is
'black'.vcolor (str, optional) – Color for the SED violin plots. Default is
'black'.pcolor (str, optional) – Color for the SED data points. Default is
'black'.R_solar (float, optional) – Solar galactocentric radius in kpc. Default is 8.2.
Z_solar (float, optional) – Solar height above midplane in kpc. Default is 0.025.
figsize (tuple, optional) – Figure size. If None, determined automatically.
rstate (~numpy.random.RandomState, optional) – Random state passed to
cornerplotandposterior_predictive. If not provided, the global numpy.random state is used.**corner_kwargs – Additional keyword arguments passed to
cornerplot.
- Returns:
fig (~matplotlib.figure.Figure) – The combined figure.
axes (~numpy.ndarray) – The corner plot axes array.
ax_sed (~matplotlib.axes.Axes) – The posterior predictive SED axes.
Distance and Reddening¶
- brutus.plotting.dist_vs_red(data, ebv=None, dist_type='distance_modulus', lndistprior=None, coord=None, avlim=(0.0, 20.0), rvlim=(1.0, 8.0), weights=None, parallax=None, parallax_err=None, Nr=300, cmap='Blues', bins=300, span=None, smooth=(0.015, 0.005), plot_kwargs=None, truths=None, truth_color='red', truth_kwargs=None, rstate=None, fig=None)[source]¶
Generate a 2-D plot of distance vs reddening.
- Parameters:
data (3-tuple or 4-tuple of ~numpy.ndarray) – Arrays of shape
(Nsamps,)or(Nobj, Nsamps)containing either saved(dists, reds, dreds)draws in(kpc, mag, -)or(scales, avs, rvs, covs_sar)used to regenerate draws under the distance and parallax priors. Saved draws are preferred because regeneration applies only the distance and parallax priors rather than the dust-map and label-dependent priors used during fitting. When(Nobj, Nsamps)arrays are passed, the plotted histogram is the mean of the per-object 2-D PDFs.ebv (bool, optional) – If True, convert \(A(V)\) to \(E(B-V) = A(V) / R(V)\). Default is
None(plot \(A(V)\) in mag).dist_type (str, optional) – Distance quantity to plot on the x-axis (
'parallax','scale','distance', or'distance_modulus'). Default is'distance_modulus'.lndistprior (func, optional) – The log-distance prior function used. If not provided, ~brutus.priors.logp_galactic_structure is assumed.
coord (2-tuple or list of 2-tuples, optional) – The galactic (l, b) coordinates passed to lndistprior. A single (l, b) pair is shared across all objects; for multi-object input a list with one pair per object is also accepted.
avlim (2-tuple, optional) – The Av limits used to truncate regenerated draws. Without span, they also set the A(V) range of the bins and of the smoothing. Default is AVLIM, (0, 20), the BruteForce.fit default.
rvlim (2-tuple, optional) – The Rv limits used to truncate results. Default is RVLIM, (1, 8).
weights (~numpy.ndarray of shape (Nsamps) or (Nobj, Nsamps), optional) – An optional set of importance weights used to reweight the samples.
parallax (float or ~numpy.ndarray of shape (Nobj,), optional) – The parallax estimate for each source in mas. A float applies to every object.
parallax_err (float or ~numpy.ndarray of shape (Nobj,), optional) – The parallax error for each source in mas. A float applies to every object.
Nr (int, optional) – The number of Monte Carlo realizations used when sampling using the provided parallax prior. Default is 300.
cmap (str, optional) – The colormap used when plotting. Default is ‘Blues’.
bins (int or list of ints with length (ndim,), optional) – The number of bins to be used in each dimension. Default is 300.
span (iterable with shape (2, 2), optional) – ((av_min, av_max), (d_min, d_max)), A(V) in mag and distance in kpc, as in bin_pdfs_distred. If not provided, A(V) spans avlim and the distance spans distance modulus 4 to 19.
smooth (float or 2-tuple of floats, optional) – The smoothing, as in bin_pdfs_distred. Default is (0.015, 0.005). The distance smoothing never exceeds what the parallax allows.
plot_kwargs (dict, optional) – Extra keyword arguments to be used when plotting the smoothed 2-D histograms.
truths (iterable with shape (ndim,), optional) – A list of reference values that will be overplotted on the traces and marginalized 1-D posteriors as solid horizontal/vertical lines. Individual values can be exempt using None. Default is None.
truth_color (str or iterable with shape (ndim,), optional) – A ~matplotlib-style color (either a single color or a different value for each subplot) used when plotting truths. Default is ‘red’.
truth_kwargs (dict, optional) – Extra keyword arguments that will be used for plotting the vertical and horizontal lines with truths.
rstate (~numpy.random.RandomState, optional) – ~numpy.random.RandomState instance.
fig ((~matplotlib.figure.Figure, ~matplotlib.axes.Axes), optional) – The figure and axes to draw on. Default is the current axes, ~matplotlib.pyplot.gca.
- Returns:
hist2d – Output 2-D histogram.
- Return type:
(counts, xedges, yedges, ~matplotlib.figure.Image)
- brutus.plotting.bin_pdfs_distred(data, cdf=False, ebv=False, dist_type='distance_modulus', lndistprior=None, coord=None, avlim=(0.0, 20.0), rvlim=(1.0, 8.0), weights=None, parallaxes=None, parallax_errors=None, Nr=100, bins=(750, 300), span=None, smooth=(0.01, 0.005), rstate=None, verbose=False, R_solar=8.2, Z_solar=0.025)[source]¶
Generate binned versions of the 2-D posteriors for the distance and reddening.
- Parameters:
data (3-tuple or 4-tuple of ~numpy.ndarray of shape (Nobj, Nsamps)) – Either saved
(dists, reds, dreds)draws in(kpc, mag, -)or(scales, avs, rvs, covs_sar)used to regenerate draws under the distance and parallax priors. Saved draws are preferred because regeneration applies only the distance and parallax priors rather than the dust-map and label-dependent priors used during fitting.cdf (bool, optional) – Whether to compute the CDF along the reddening axis instead of the PDF. Useful when evaluating the MAP LOS fit. Default is False.
ebv (bool, optional) – If provided, will convert from Av to E(B-V) when plotting using the provided Rv values. Default is False.
dist_type (str, optional) – Distance quantity for the x-axis (
'parallax','scale','distance', or'distance_modulus'). Default is'distance_modulus'.lndistprior (func, optional) – The log-distance prior function used. If not provided, ~brutus.priors.logp_galactic_structure is assumed.
coord (2-tuple or ~numpy.ndarray of shape (Nobj, 2), optional) – The galactic (l, b) coordinates passed to lndistprior when re-generating the fits. A single (l, b) pair is shared across all objects; otherwise provide one pair per object.
avlim (2-tuple, optional) – The Av limits used to truncate regenerated draws. Without span, they also set the A(V) range of the bins and of the smoothing. Default is AVLIM, (0, 20), the BruteForce.fit default.
rvlim (2-tuple, optional) – The Rv limits used to truncate results. Default is RVLIM, (1, 8).
weights (~numpy.ndarray of shape (Nobj, Nsamps), optional) – An optional set of importance weights used to reweight the samples. Must be finite and non-negative, with at least one positive weight per object. Each object’s binned PDF is normalized by its total weight, so results are invariant to the absolute scale of weights.
parallaxes (float or ~numpy.ndarray of shape (Nobj,), optional) – The parallax estimates for the sources in mas. A float applies to every object.
parallax_errors (float or ~numpy.ndarray of shape (Nobj,), optional) – The parallax errors for the sources in mas. A float applies to every object.
Nr (int, optional) – The number of Monte Carlo realizations used when sampling using the provided parallax prior. Default is 100.
bins (int or list of ints with length (ndim,), optional) – The number of bins to be used in each dimension. Default is (750, 300) (distance, reddening).
span (array_like of shape (2, 2), optional) – Bounds
((av_min, av_max), (d_min, d_max))giving the \(A(V)\) range of the y-axis in mag and the distance range of the x-axis in kpc (converted internally todist_type). Note thatspanorders \(A(V)\) before distance, whereasbinsandsmoothorder distance before \(A(V)\). If not provided, the y-axis spansavlimand the x-axis spans distance modulus 4 to 19 (0.063 to 63.1 kpc).smooth (float or 2-tuple of floats, optional) – The standard deviation of the Gaussian kernel that smooths the 2-D PDFs, as (distance, A(V)) or one value for both axes. A value below 1 is a fraction of that axis range, and a value of 1 or more is a number of bins. Without span, the A(V) range is avlim, so with the default avlim an A(V) value of 0.005 is 0.1 mag (of E(B-V) with ebv=True, since the axis keeps the avlim range). Default is (0.01, 0.005).
rstate (~numpy.random.RandomState, optional) – ~numpy.random.RandomState instance.
verbose (bool, optional) – Whether to print progress to ~sys.stderr. Default is False.
R_solar (float, optional) – Solar Galactocentric radius in kpc passed to the default distance prior. Default is 8.2.
Z_solar (float, optional) – Solar height above the Galactic midplane in kpc passed to the default distance prior. Default is 0.025.
- Returns:
binned_vals (~numpy.ndarray of shape (Nobj, Nxbin, Nybin)) – Binned 2-D PDFs (or cumulative distributions along reddening when
cdf=True).xedges (~numpy.ndarray of shape (Nxbin+1,)) – The edges defining the bins in distance.
yedges (~numpy.ndarray of shape (Nybin+1,)) – The edges defining the bins in reddening.
Photometric Offsets¶
- brutus.plotting.photometric_offsets(phot, err, mask, models, idxs, reds, dreds, dists, x=None, flux=True, weights=None, bins=100, offset=None, plot_thresh=0.0, cmap='viridis', xspan=None, yspan=None, titles=None, xlabel=None, plot_kwargs=None, fig=None)[source]¶
Plot photometric offsets (mag_pred - mag_obs).
The draws of each object are weighted, band by band, with the leave-one-out weights of brutus.analysis.photometric_offsets, \(w \propto \exp(\chi^2_i / 2)\) times weights, where \(\chi^2_i\) is the flux-space chi-square of band i. They use phot and err as given; offset only shifts the plotted residuals.
- Parameters:
phot (~numpy.ndarray of shape (Nobj, Nfilt)) – Observed flux densities in maggies (when
flux=True) or observed magnitudes (whenflux=False).err (~numpy.ndarray of shape (Nobj, Nfilt)) – Uncertainties on
photin the same units asphot.mask (~numpy.ndarray of shape (Nobj, Nfilt)) – Boolean (or 0/1) mask indicating observed bands.
models (~numpy.ndarray of shape (Nmodels, Nfilts, Ncoeffs)) – Array of magnitude polynomial coefficients used to generate reddened photometry.
idxs (~numpy.ndarray of shape (Nobj, Nsamps)) – An array of resampled indices corresponding to the set of models used to fit the data.
reds (~numpy.ndarray of shape (Nobj, Nsamps)) – Reddening samples (in Av) associated with the model indices.
dreds (~numpy.ndarray of shape (Nobj, Nsamps)) – “Differential” reddening samples (in Rv) associated with the model indices.
dists (~numpy.ndarray of shape (Nobj, Nsamps)) – Distance samples (in kpc) associated with the model indices.
x (~numpy.ndarray with shape (Nobj,) or (Nobj, Nsamps), optional) – Corresponding values to be plotted on the x axis. If not provided, the default behavior is to plot as a function of observed magnitude.
flux (bool, optional) – Whether the photometry provided is in fluxes (instead of magnitudes). Default is True.
weights (~numpy.ndarray of shape (Nobj,) or (Nobj, Nsamps), optional) – Importance weights of the objects or of their samples. Any other shape raises ValueError.
bins (int or sequence of Nfilt ints, optional) – The number of bins along both axes of each panel, for all bands or one value per band. Any other input raises ValueError. Default is 100.
offset (~numpy.ndarray of shape (Nfilt), optional) – Multiplicative flux offsets. They shift the plotted residuals by 2.5 log10(offset) and do not change the weights.
plot_thresh (float, optional) – The minimum summed weight of a bin to be colored, passed to ~matplotlib.axes.Axes.hist2d as cmin. The draws of each object sum to 1 in each band. Default is 0..
cmap (colormap, optional) – The colormap used when plotting results. Default is ‘viridis’.
xspan (iterable with shape (nfilt, 2), optional) – A list where each element is a length-2 tuple containing lower and upper bounds for the x-axis for each plot.
yspan (iterable with shape (nfilt, 2), optional) – A list where each element is a length-2 tuple containing lower and upper bounds for the y-axis for each plot.
titles (iterable of str of length Nfilt, optional) – Titles for each of the subplots corresponding to each band. If not provided Band # will be used.
xlabel (str, optional) – Label for the x-axis of each subplot. If not provided, it is the title of the subplot when x is not given, and ‘Label’ otherwise.
plot_kwargs (kwargs, optional) – Keyword arguments to be passed to ~matplotlib.axes.Axes.hist2d.
fig ((~matplotlib.figure.Figure, ~matplotlib.axes.Axes), optional) – If provided, draw on the provided axes, one per band, and leave the figure layout unchanged. Otherwise, a new figure is generated and laid out with ~matplotlib.figure.Figure.tight_layout.
- Returns:
postpredplot – The associated figure and axes for the photometric offsets.
- Return type:
(~matplotlib.figure.Figure, ~matplotlib.axes.Axes)
- brutus.plotting.photometric_offsets_2d(phot, err, mask, models, idxs, reds, dreds, dists, x, y, flux=True, weights=None, bins=100, offset=None, plot_thresh=10.0, cmap='coolwarm', clims=(-0.05, 0.05), xspan=None, yspan=None, titles=None, show_off=True, xlabel=None, ylabel=None, plot_kwargs=None, fig=None)[source]¶
Plot photometric offsets (mag_pred - mag_obs).
The draws of each object are weighted, band by band, with the leave-one-out weights of brutus.analysis.photometric_offsets, \(w \propto \exp(\chi^2_i / 2)\) times weights, where \(\chi^2_i\) is the flux-space chi-square of band i. They use phot and err as given; offset only shifts the plotted residuals.
- Parameters:
phot (~numpy.ndarray of shape (Nobj, Nfilt)) – Observed flux densities in maggies (when
flux=True) or observed magnitudes (whenflux=False).err (~numpy.ndarray of shape (Nobj, Nfilt)) – Uncertainties on
photin the same units asphot.mask (~numpy.ndarray of shape (Nobj, Nfilt)) – Boolean (or 0/1) mask indicating observed bands.
models (~numpy.ndarray of shape (Nmodels, Nfilts, Ncoeffs)) – Array of magnitude polynomial coefficients used to generate reddened photometry.
idxs (~numpy.ndarray of shape (Nobj, Nsamps)) – An array of resampled indices corresponding to the set of models used to fit the data.
reds (~numpy.ndarray of shape (Nobj, Nsamps)) – Reddening samples (in Av) associated with the model indices.
dreds (~numpy.ndarray of shape (Nobj, Nsamps)) – “Differential” reddening samples (in Rv) associated with the model indices.
dists (~numpy.ndarray of shape (Nobj, Nsamps)) – Distance samples (in kpc) associated with the model indices.
x (~numpy.ndarray with shape (Nobj,)) – Values to be plotted on the x axis. Required.
y (~numpy.ndarray with shape (Nobj,)) – Values to be plotted on the y axis. Required.
flux (bool, optional) – Whether the photometry provided is in fluxes (instead of magnitudes). Default is True.
weights (~numpy.ndarray of shape (Nobj,) or (Nobj, Nsamps), optional) – Importance weights of the objects or of their samples. Any other shape raises ValueError.
bins (int, (int, int) or sequence of Nfilt of these, optional) – The number of bins of each map: one int for both axes, an (nx, ny) pair, or one of these per band. A sequence of length Nfilt is read as one entry per band. Default is 100.
offset (~numpy.ndarray of shape (Nfilt), optional) – Multiplicative flux offsets. They shift the plotted residuals by 2.5 log10(offset) and do not change the weights.
plot_thresh (float, optional) – The minimum number of objects in a bin. Bins with fewer objects, or with zero total weight, are masked. Default is 10..
cmap (colormap, optional) – The colormap used when plotting results. Default is ‘coolwarm’.
clims (2-tuple, optional) – Plotting bounds for the colorbar. Default is (-0.05, 0.05).
xspan (iterable with shape (nfilt, 2), optional) – The (low, high) range of the x bins of each map. If not provided, the bins span the range of x.
yspan (iterable with shape (nfilt, 2), optional) – The (low, high) range of the y bins of each map. If not provided, the bins span the range of y.
titles (iterable of str of length Nfilt, optional) – Titles for each of the subplots corresponding to each band. If not provided Band # will be used.
show_off (bool, optional) – Whether to include the offsets in the titles. Default is True.
xlabel (str, optional) – Label for the x-axis of each subplot. If not provided, this will default to X.
ylabel (str, optional) – Label for the y-axis of each subplot. If not provided, this will default to Y.
plot_kwargs (kwargs, optional) – Keyword arguments to be passed to ~matplotlib.axes.Axes.imshow.
fig ((~matplotlib.figure.Figure, ~matplotlib.axes.Axes), optional) – If provided, draw on the provided axes, one per band, and leave the figure layout unchanged. Otherwise, a new figure is generated and laid out with ~matplotlib.figure.Figure.tight_layout.
- Returns:
postpredplot – The associated figure and axes for the photometric offsets.
- Return type:
(~matplotlib.figure.Figure, ~matplotlib.axes.Axes)
Plotting Utilities¶
- brutus.plotting.hist2d(x, y, smooth=0.02, span=None, weights=None, levels=None, ax=None, color='gray', plot_datapoints=False, plot_density=True, plot_contours=True, no_fill_contours=False, fill_contours=True, contour_kwargs=None, contourf_kwargs=None, data_kwargs=None)[source]¶
Plot a 2-D histogram and contours of weighted samples.
The plot is drawn on ax, with its limits set to span.
- Parameters:
x (iterable with shape (nsamps,)) – Sample positions in the first dimension.
y (iterable with shape (nsamps,)) – Sample positions in the second dimension.
smooth (int, float or 2-tuple of these, optional) – The binning of each axis, one value for both or one per axis. A float is the standard deviation of the Gaussian kernel that smooths the histogram, as a fraction of the span. An int is a number of bins, with no smoothing. Default is 0.02.
span (iterable of length 2, optional) –
Per-axis bounds where each element is either a
(low, high)tuple or a float in(0., 1.]giving the equal-tailed weighted credible fraction to include, for example:span = [(0.0, 10.0), 0.95]
Default is
0.99(99% credible interval on each axis).weights (iterable with shape (nsamps,)) – Weights associated with the samples. Default is None (no weights).
levels (iterable, optional) – The contour levels to draw. Default are [0.5, 1, 1.5, 2]-sigma.
ax (~matplotlib.axes.Axes, optional) – An ~matplotlib.axes.axes instance on which to add the 2-D histogram. If not provided, a figure will be generated.
color (str, optional) – The ~matplotlib-style color used to draw lines and color cells and contours. Default is ‘gray’.
plot_datapoints (bool, optional) – Whether to plot the individual data points. Default is False.
plot_density (bool, optional) – Whether to draw the density colormap. Default is True.
plot_contours (bool, optional) – Whether to draw the contours. Default is True.
no_fill_contours (bool, optional) – Whether to add absolutely no filling to the contours. This differs from fill_contours=False, which still adds a white fill at the densest points. Default is False.
fill_contours (bool, optional) – Whether to fill the contours. Default is True.
contour_kwargs (dict) – Any additional keyword arguments to pass to the contour method.
contourf_kwargs (dict) – Any additional keyword arguments to pass to the contourf method.
data_kwargs (dict) – Any additional keyword arguments to pass to the plot method when adding the individual data points.