mantispy.pl.density

Contents

mantispy.pl.density#

mantispy.pl.density(adata, feature, groupby='Metadata_Perturbation', key='Metadata_LocalDensity', max_groups=6, ax=None)[source]#

Local cell density against a feature, per group.

Crowding alone changes morphology. Use this plot to check whether density explains a phenotype before regressing it out with regress_out(). A group whose points fall on the same line as the controls differs from them only in density.

Parameters:
  • adata (AnnData) – Single-cell object carrying the density column and the feature.

  • feature (str) – Feature to plot against density.

  • groupby (str (default: 'Metadata_Perturbation')) – Column defining the groups drawn.

  • key (str (default: 'Metadata_LocalDensity')) – obs column holding the local density.

  • max_groups (int (default: 6)) – Number of groups drawn, largest first.

  • ax (Axes | None (default: None)) – Axes to draw on.

Return type:

Axes | None

Returns:

The axes when the caller passed ax, else None because the plot then owns the figure it created. When returned they hold a scatter and a fitted line per group and each group’s Pearson correlation between density and the feature in the legend. A group with fewer than three usable points is left out.

Raises:

KeyError – obs has no key column, or feature is not one of var_names.