bebi103.viz.contour_lines_from_samples

bebi103.viz.contour_lines_from_samples(x, y, smooth=0.02, levels=None, bins=50, weights=None, extend_domain=False)

Get lines for a contour plot from (x, y) samples.

Parameters
  • x (array_like, shape (n,)) – x-values of samples.

  • y (array_like, shape (n,)) – y-values of samples.

  • smooth (float, default 0.02) – Smoothing parameter for Gaussian smoothing of contour. A Gaussian filter is applied with standard deviation given by smooth * bins. If None, no smoothing is done.

  • levels (float, list of floats, or None) – The levels of the contours. To enclose 95% of the samples, use levels=0.95. If provided as a list, multiple levels are used. If None, levels is approximately [0.12, 0.39, 0.68, 0.86].

  • bins (int, default 50) – Binning of samples into square bins is necessary to construct the contours. bins gives the number of bins in each direction.

  • weights (array_like, shape (n,), default None) – Weights to apply to each sample in constructing the histogram. Default is None, such that all samples are equally weighted.

  • extend_domain (bool, default False) – If True, extend the domain of the contours beyond the domain of the min and max of the samples. This can be useful if the contours might clash with the edges of a plot.

Returns

  • xs (list of arrays) – Each array is the x-values for a plotted contour

  • ys (list of arrays) – Each array is the y-values for a plotted contour

Notes

The method proceeds as follows: the samples are binned. The counts of samples landing in bins are thought of as values of a function f(xb, yb), where (xb, yb) denotes the center of the respective bins. This function is then optionally smoothed using a Gaussian blur, and then the result is used to construct a contour plot.

Based heavily on code from the corner package by Dan Forman-Mackey.