gwin.results.scatter_histograms module

Module to generate figures with scatter plots and histograms.

gwin.results.scatter_histograms.construct_kde(samples_array, use_kombine=False)[source]

Constructs a KDE from the given samples.

gwin.results.scatter_histograms.create_axes_grid(parameters, labels=None, height_ratios=None, width_ratios=None, no_diagonals=False)[source]

Given a list of parameters, creates a figure with an axis for every possible combination of the parameters.

Parameters:
  • parameters (list) – Names of the variables to be plotted.
  • labels ({None, dict}, optional) – A dictionary of parameters -> parameter labels.
  • height_ratios ({None, list}, optional) – Set the height ratios of the axes; see matplotlib.gridspec.GridSpec for details.
  • width_ratios ({None, list}, optional) – Set the width ratios of the axes; see matplotlib.gridspec.GridSpec for details.
  • no_diagonals ({False, bool}, optional) – Do not produce axes for the same parameter on both axes.
Returns:

  • fig (pyplot.figure) – The figure that was created.
  • axis_dict (dict) – A dictionary mapping the parameter combinations to the axis and their location in the subplots grid; i.e., the key, values are: {('param1', 'param2'): (pyplot.axes, row index, column index)}

gwin.results.scatter_histograms.create_density_plot(xparam, yparam, samples, plot_density=True, plot_contours=True, percentiles=None, cmap='viridis', contour_color=None, xmin=None, xmax=None, ymin=None, ymax=None, exclude_region=None, fig=None, ax=None, use_kombine=False)[source]

Computes and plots posterior density and confidence intervals using the given samples.

Parameters:
  • xparam (string) – The parameter to plot on the x-axis.
  • yparam (string) – The parameter to plot on the y-axis.
  • samples (dict, numpy structured array, or FieldArray) – The samples to plot.
  • plot_density ({True, bool}) – Plot a color map of the density.
  • plot_contours ({True, bool}) – Plot contours showing the n-th percentiles of the density.
  • percentiles ({None, float or array}) – What percentile contours to draw. If None, will plot the 50th and 90th percentiles.
  • cmap ({'viridis', string}) – The name of the colormap to use for the density plot.
  • contour_color ({None, string}) – What color to make the contours. Default is white for density plots and black for other plots.
  • xmin ({None, float}) – Minimum value to plot on x-axis.
  • xmax ({None, float}) – Maximum value to plot on x-axis.
  • ymin ({None, float}) – Minimum value to plot on y-axis.
  • ymax ({None, float}) – Maximum value to plot on y-axis.
  • exclue_region ({None, str}) – Exclude the specified region when plotting the density or contours. Must be a string in terms of xparam and yparam that is understandable by numpy’s logical evaluation. For example, if xparam = m_1 and yparam = m_2, and you want to exclude the region for which m_2 is greater than m_1, then exclude region should be 'm_2 > m_1'.
  • fig ({None, pyplot.figure}) – Add the plot to the given figure. If None and ax is None, will create a new figure.
  • ax ({None, pyplot.axes}) – Draw plot on the given axis. If None, will create a new axis from fig.
  • use_kombine ({False, bool}) – Use kombine’s KDE to calculate density. Otherwise, will use scipy.stats.gaussian_kde. Default is False.
Returns:

  • fig (pyplot.figure) – The figure the plot was made on.
  • ax (pyplot.axes) – The axes the plot was drawn on.

gwin.results.scatter_histograms.create_marginalized_hist(ax, values, label, percentiles=None, color='k', fillcolor='gray', linecolor='navy', title=True, expected_value=None, expected_color='red', rotated=False, plot_min=None, plot_max=None)[source]

Plots a 1D marginalized histogram of the given param from the given samples.

Parameters:
  • ax (pyplot.Axes) – The axes on which to draw the plot.
  • values (array) – The parameter values to plot.
  • label (str) – A label to use for the title.
  • percentiles ({None, float or array}) – What percentiles to draw lines at. If None, will draw lines at [5, 50, 95] (i.e., the bounds on the upper 90th percentile and the median).
  • color ({'k', string}) – What color to make the histogram; default is black.
  • fillcolor ({'gray', string, or None}) – What color to fill the histogram with. Set to None to not fill the histogram. Default is ‘gray’.
  • linecolor ({'navy', string}) – What color to use for the percentile lines. Default is ‘navy’.
  • title ({True, bool}) – Add a title with the median value +/- uncertainty, with the max(min) percentile used for the +(-) uncertainty.
  • rotated ({False, bool}) – Plot the histogram on the y-axis instead of the x. Default is False.
  • plot_min ({None, float}) – The minimum value to plot. If None, will default to whatever pyplot creates.
  • plot_max ({None, float}) – The maximum value to plot. If None, will default to whatever pyplot creates.
  • scalefac ({1., float}) – Factor to scale the default font sizes by. Default is 1 (no scaling).
gwin.results.scatter_histograms.create_multidim_plot(parameters, samples, labels=None, mins=None, maxs=None, expected_parameters=None, expected_parameters_color='r', plot_marginal=True, plot_scatter=True, marginal_percentiles=None, contour_percentiles=None, zvals=None, show_colorbar=True, cbar_label=None, vmin=None, vmax=None, scatter_cmap='plasma', plot_density=False, plot_contours=True, density_cmap='viridis', contour_color=None, hist_color='black', line_color=None, fill_color='gray', use_kombine=False, fig=None, axis_dict=None)[source]

Generate a figure with several plots and histograms.

Parameters:
  • parameters (list) – Names of the variables to be plotted.
  • samples (FieldArray) – A field array of the samples to plot.
  • labels ({None, list}, optional) – A list of names for the parameters.
  • mins ({None, dict}, optional) – Minimum value for the axis of each variable in parameters. If None, it will use the minimum of the corresponding variable in samples.
  • maxs ({None, dict}, optional) – Maximum value for the axis of each variable in parameters. If None, it will use the maximum of the corresponding variable in samples.
  • expected_parameters ({None, dict}, optional) – Expected values of parameters, as a dictionary mapping parameter names -> values. A cross will be plotted at the location of the expected parameters on axes that plot any of the expected parameters.
  • expected_parameters_color ({'r', string}, optional) – What color to make the expected parameters cross.
  • plot_marginal ({True, bool}) – Plot the marginalized distribution on the diagonals. If False, the diagonal axes will be turned off.
  • plot_scatter ({True, bool}) – Plot each sample point as a scatter plot.
  • marginal_percentiles ({None, array}) – What percentiles to draw lines at on the 1D histograms. If None, will draw lines at [5, 50, 95] (i.e., the bounds on the upper 90th percentile and the median).
  • contour_percentiles ({None, array}) – What percentile contours to draw on the scatter plots. If None, will plot the 50th and 90th percentiles.
  • zvals ({None, array}) – An array to use for coloring the scatter plots. If None, scatter points will be the same color.
  • show_colorbar ({True, bool}) – Show the colorbar of zvalues used for the scatter points. A ValueError will be raised if zvals is None and this is True.
  • cbar_label ({None, str}) – Specify a label to add to the colorbar.
  • vmin ({None, float}, optional) – Minimum value for the colorbar. If None, will use the minimum of zvals.
  • vmax ({None, float}, optional) – Maximum value for the colorbar. If None, will use the maxmimum of zvals.
  • scatter_cmap ({'plasma', string}) – The color map to use for the scatter points. Default is ‘plasma’.
  • plot_density ({False, bool}) – Plot the density of points as a color map.
  • plot_contours ({True, bool}) – Draw contours showing the 50th and 90th percentile confidence regions.
  • density_cmap ({'viridis', string}) – The color map to use for the density plot.
  • contour_color ({None, string}) – The color to use for the contour lines. Defaults to white for density plots, navy for scatter plots without zvals, and black otherwise.
  • use_kombine ({False, bool}) – Use kombine’s KDE to calculate density. Otherwise, will use scipy.stats.gaussian_kde. Default is False.
Returns:

  • fig (pyplot.figure) – The figure that was created.
  • axis_dict (dict) – A dictionary mapping the parameter combinations to the axis and their location in the subplots grid; i.e., the key, values are: {('param1', 'param2'): (pyplot.axes, row index, column index)}

gwin.results.scatter_histograms.get_scale_fac(fig, fiducial_width=8, fiducial_height=7)[source]

Gets a factor to scale fonts by for the given figure. The scale factor is relative to a figure with dimensions (fiducial_width, fiducial_height).

gwin.results.scatter_histograms.reduce_ticks(ax, which, maxticks=3)[source]

Given a pyplot axis, resamples its which-axis ticks such that are at most maxticks left.

Parameters:
  • ax (axis) – The axis to adjust.
  • which ({'x' | 'y'}) – Which axis to adjust.
  • maxticks ({3, int}) – Maximum number of ticks to use.
Returns:

An array of the selected ticks.

Return type:

array

gwin.results.scatter_histograms.remove_common_offset(arr)[source]

Given an array of data, removes a common offset > 1000, returning the removed value.

gwin.results.scatter_histograms.set_marginal_histogram_title(ax, fmt, color, label=None, rotated=False)[source]

Sets the title of the marginal histograms.

Parameters:
  • ax (Axes) – The Axes instance for the plot.
  • fmt (str) – The string to add to the title.
  • color (str) – The color of the text to add to the title.
  • label (str) – If title does not exist, then include label at beginning of the string.
  • rotated (bool) – If True then rotate the text 270 degrees for sideways title.