monkeybread.plot.location_and_density

monkeybread.plot.location_and_density(adata, groupby, groups, groupnames=None, plot_density=True, resolution=10, bandwsith=75, dot_size=7, na_dot_size=1.5, title=None, grid=True, n_grids=5, palette=None, delete_temp_columns=False, show=True)

A wrapper around both scanpy.pl.embedding() and monkeybread.calc.cell_density() that creates multi-panel figures showing both the raw location of cells of a given cell type, by calling scanpy.pl.embedding() and their density across the tissue by calling monkeybread.calc.cell_density().

Parameters:
  • adata (AnnData) – Annotated data matrix.

  • groupby (str) – A key in adata.obs that store the cell type labels to be plotted.

  • groups (Union[str, List[str], List[List[str]]]) – Either a single cell type label in adata.obs[{key}], a list of cell type labels in adata.obs[{key}], or a list of lists of cell type labels in adata.obs[{key}]. If provided a list of lists, then each sub-list is considered one cell type and a union of all labels in that sublist will be used to group the cells (e.g., [[‘CD4 memory T cell’, ‘CD4 naive T cell’], [‘CD8 memory T cell’, ‘CD8 naive T cell’]] encodes two groups of cells: CD4 T cells and CD8 T cells)

  • groupnames (Union[str, List[str], None] (default: None)) – If groups is a list of lists, then this list of groupnames stores a list of strings corresponding to each sublist and is used to label the cells in that group. (e.g., in the example above, such a list might be [‘CD4 T cell’, ‘CD8 T cell’] that will label the CD4 and CD8 T cells)

  • plot_density (Optional[bool] (default: True)) – Plot the density plots alongside the embedding plot.

  • resolution (Optional[bool] (default: 10)) – Resolution parameter to pass to monkeybread.calc.cell_density()

  • bandwidth – Bandwidth parameter to pass to monkeybread.calc.cell_density()

  • dot_size (Union[float, List[float], None] (default: 7)) – The size of dots in the embedding for the cells of intests (specified in groups). To plot each group with a different dot size, a list of sizes can be provided.

  • na_dot_size (Optional[float] (default: 1.5)) – The size of dots in the embedding for cells that are not of interest (specified in groups)

  • title (Optional[str] (default: None)) – Title of the first figure showing the embedding of all of the cells together in one plot.

  • grid (Optional[bool] (default: True)) – If True, draw grid lines in each plot

  • n_grids (Optional[int] (default: 5)) – Number of gridlines to be drawn if grid is True

  • palette (Optional[List[str]] (default: None)) – Color palette used to color each group

  • delete_temp_columns (Optional[bool] (default: False)) – Delete columns added to adata.obs that were added during the creation of these plots.

  • show (Optional[bool] (default: True)) – If True display the figure. Otherwise return the plt.Figure and plt.Axes objects.

Return type:

Optional[Tuple[Figure, List[Axes]]]

Returns:

: If show = False returns the current figure and axes. If show = True returns nothing.

Example

The left-most figure displays the locations of B cells (red) and CD4 Tfh cells (blue) in the tissue. The center and right-most figures display the density of B cells and CD4 Tfh cells, respectively, across the tissue.

https://raw.githubusercontent.com/immunitastx/monkeybread/main/docs/_static/location_and_density.png