lib5c.plotters.variance module

Module for plotting mean-variance relationships.

lib5c.plotters.variance.plot_mvr(exp, var, obs=None, num_groups=100, group_fractional_tolerance=0.1, exclude_offdiagonals=5, log=False, logx=False, logy=False, vst=False, scatter=False, hexbin=False, trim_limits=False, xlim=None, ylim=None, **kwargs)[source]

Plots a scatterplot of exp vs var.

Optionally, pass obs to instead scatterplot exp vs freshly re-estimated group variances, and overlay exp vs var as a smooth curve.

Parameters
  • exp (np.ndarray or dict of np.ndarray) – Regional matrix of expected values. Pass a counts dict to combine all regions together.

  • var (np.ndarray or dict of np.ndarray) – Regional matrix of variances. Pass a counts dict to combine all regions together.

  • obs (np.ndarray or dict of np.ndarray, optional) – Regional matrix of observed values. Pass a counts dict to combine all regions together.

  • num_groups (int) – The number of groups to re-esimtate group variances for.

  • group_fractional_tolerance (float) – The width of each group, specified as a fractional tolerance in the expected value.

  • exclude_offdiagonals (int) – Exclude this many off-diagonals from the variance re-estimation. Pass 0 to exclude only the exact diagonal. Pass -1 to exclude nothing.

  • log (bool) – Pass True to log both exp and var.

  • logy (logx,) – Pass True to draw the x- and/or y-axis on a log-scale.

  • vst (bool) – Pass True to log only the exp (e.g., when var is already stabilized).

  • scatter (bool) – Pass True to force plotting exp vs var as a scatterplot when obs is not passed. By default it will be a line plot.

  • hexbin (bool) – Pass True when scatter=True to replace the scatterplot with a hexbin plot.

  • trim_limits (bool) – If obs is passed, pass True to trim the x- and y-limits to the range of the group expected and variance values.

  • kwargs (kwargs) – Typical plotter kwargs.

Returns

The axis plotted on.

Return type

pyplot axis

lib5c.plotters.variance.plot_mvr_parallel(exp, var, obs=None, num_groups=100, group_fractional_tolerance=0.1, exclude_offdiagonals=5, log=False, logx=False, logy=False, vst=False, scatter=False, hexbin=False, trim_limits=False, xlim=None, ylim=None, **kwargs)

Plots a scatterplot of exp vs var.

Optionally, pass obs to instead scatterplot exp vs freshly re-estimated group variances, and overlay exp vs var as a smooth curve.

Parameters
  • exp (np.ndarray or dict of np.ndarray) – Regional matrix of expected values. Pass a counts dict to combine all regions together.

  • var (np.ndarray or dict of np.ndarray) – Regional matrix of variances. Pass a counts dict to combine all regions together.

  • obs (np.ndarray or dict of np.ndarray, optional) – Regional matrix of observed values. Pass a counts dict to combine all regions together.

  • num_groups (int) – The number of groups to re-esimtate group variances for.

  • group_fractional_tolerance (float) – The width of each group, specified as a fractional tolerance in the expected value.

  • exclude_offdiagonals (int) – Exclude this many off-diagonals from the variance re-estimation. Pass 0 to exclude only the exact diagonal. Pass -1 to exclude nothing.

  • log (bool) – Pass True to log both exp and var.

  • logy (logx,) – Pass True to draw the x- and/or y-axis on a log-scale.

  • vst (bool) – Pass True to log only the exp (e.g., when var is already stabilized).

  • scatter (bool) – Pass True to force plotting exp vs var as a scatterplot when obs is not passed. By default it will be a line plot.

  • hexbin (bool) – Pass True when scatter=True to replace the scatterplot with a hexbin plot.

  • trim_limits (bool) – If obs is passed, pass True to trim the x- and y-limits to the range of the group expected and variance values.

  • kwargs (kwargs) – Typical plotter kwargs.

Returns

The axis plotted on.

Return type

pyplot axis

lib5c.plotters.variance.plot_overlay_mvr(exp, var, obs=None, num_groups=100, group_fractional_tolerance=0.1, exclude_offdiagonals=5, log=False, logx=False, logy=False, vst=False, scatter=False, scatter_colors=None, line_colors=None, legend='outside', **kwargs)[source]

Plots a comparison of mean-variance relationships across regions.

Parameters
  • exp (dict of np.ndarray) – Counts dict of expected values.

  • var (dict of np.ndarray) – Counts dict of variance values.

  • obs (dict of np.ndarray, optional) – Counts dict of observed values.

  • num_groups (int) – The number of groups to re-esimtate group variances for.

  • group_fractional_tolerance (float) – The width of each group, specified as a fractional tolerance in the expected value.

  • exclude_offdiagonals (int) – Exclude this many off-diagonals from the variance re-estimation. Pass 0 to exclude only the exact diagonal. Pass -1 to exclude nothing.

  • log (bool) – Pass True to log both exp and var.

  • logy (logx,) – Pass True to draw the x- and/or y-axis on a log-scale.

  • vst (bool) – Pass True to log only the exp (e.g., when var is already stabilized).

  • scatter (bool) – Pass True to force plotting exp vs var as a scatterplot when obs is not passed. By default it will be a line plot.

  • line_colors (scatter_colors,) – Mapping from region names to the color to use for that region. Pass None to use randomly assigned colors. Pass a single string to use the same color for all regions.

  • kwargs (kwargs) – Typical plotter kwargs.

Returns

The axis plotted on.

Return type

pyplot axis

lib5c.plotters.variance.prepare_exp_var_for_plotting(exp, var, obs=None, num_groups=100, group_fractional_tolerance=0.1, exclude_offdiagonals=5, log=False, vst=False)[source]

Prepares expected value and variance data for plotting.

Parameters
  • exp (np.ndarray or dict of np.ndarray) – Regional matrix of expected values. Pass a counts dict to combine all regions together.

  • var (np.ndarray or dict of np.ndarray) – Regional matrix of variances. Pass a counts dict to combine all regions together.

  • obs (np.ndarray or dict of np.ndarray, optional) – Regional matrix of observed values. Pass a counts dict to combine all regions together.

  • num_groups (int) – The number of groups to re-esimtate group variances for.

  • group_fractional_tolerance (float) – The width of each group, specified as a fractional tolerance in the expected value.

  • exclude_offdiagonals (int) – Exclude this many off-diagonals from the variance re-estimation. Pass 0 to exclude only the exact diagonal. Pass -1 to exclude nothing.

  • log (bool) – Pass True to log both exp and var.

  • vst (bool) – Pass True to log only the exp (e.g., when var is already stabilized).

Returns

The first and second elements are parallel arrays of the exp, var pairs. The third element is a sort index into the exp, var pairs. The fourth and fifth elements are None if obs was not passed. If obs was passed, they are parallel arrays of raw obs, raw var pairs.

Return type

tuple of np.ndarray

lib5c.plotters.variance.prepare_exp_var_for_plotting_parallel(exp, var, obs=None, num_groups=100, group_fractional_tolerance=0.1, exclude_offdiagonals=5, log=False, vst=False)

Prepares expected value and variance data for plotting.

Parameters
  • exp (np.ndarray or dict of np.ndarray) – Regional matrix of expected values. Pass a counts dict to combine all regions together.

  • var (np.ndarray or dict of np.ndarray) – Regional matrix of variances. Pass a counts dict to combine all regions together.

  • obs (np.ndarray or dict of np.ndarray, optional) – Regional matrix of observed values. Pass a counts dict to combine all regions together.

  • num_groups (int) – The number of groups to re-esimtate group variances for.

  • group_fractional_tolerance (float) – The width of each group, specified as a fractional tolerance in the expected value.

  • exclude_offdiagonals (int) – Exclude this many off-diagonals from the variance re-estimation. Pass 0 to exclude only the exact diagonal. Pass -1 to exclude nothing.

  • log (bool) – Pass True to log both exp and var.

  • vst (bool) – Pass True to log only the exp (e.g., when var is already stabilized).

Returns

The first and second elements are parallel arrays of the exp, var pairs. The third element is a sort index into the exp, var pairs. The fourth and fifth elements are None if obs was not passed. If obs was passed, they are parallel arrays of raw obs, raw var pairs.

Return type

tuple of np.ndarray