dynamo.pl.nneighbors

dynamo.pl.nneighbors(adata, x=0, y=1, color=['ntr'], basis=['umap'], layer=['X'], highlights=None, ncols=1, edge_bundling=None, edge_cmap='gray_r', show_points=True, labels=None, values=None, theme=None, cmap='Blues', color_key=None, color_key_cmap='Spectral', background='black', figsize=(6, 4), ax=None, save_show_or_return='return', save_kwargs={})[source]

Plot nearest neighbor graph of cells used to embed data into low dimension space.

Parameters:
  • adata (AnnData) – an Annodata object that include the umap embedding and simplicial graph.

  • x (int) – the first component of the embedding. Defaults to 0.

  • y (int) – the second component of the embedding. Defaults to 1.

  • color (List[str]) – gene name(s) or cell annotation column(s) used for coloring the graph. Defaults to [“ntr”].

  • basis (List[str]) – the low dimensional embedding to be used to visualize the cell. Defaults to [“umap”].

  • layer (List[str]) – the layers of data representing the gene expression level. Defaults to [“X”].

  • highlights (Optional[list]) – the list that cells will be restricted to. Defaults to None.

  • ncols (int) – the number of columns to be plotted. Defaults to 1.

  • edge_bundling (Optional[Literal['hammer']]) – the edge bundling method to use. Currently supported are None or ‘hammer’. See the datashader docs on graph visualization for more details. Defaults to None.

  • edge_cmap (str) – the name of a matplotlib colormap to use for shading/coloring the edges of the connectivity graph. Note that the theme, if specified, will override this. Defaults to “gray_r”.

  • show_points (bool) – whether to display the points over top of the edge connectivity. Further options allow for coloring/shading the points accordingly. Defaults to True.

  • labels (Optional[list]) – an array of labels (assumed integer or categorical), one for each data sample. This will be used for coloring the points in the plot according to their label. Note that this option is mutually exclusive to the values option. Defaults to None.

  • values (Optional[list]) – an array of values (assumed float or continuous), one for each sample. This will be used for coloring the points in the plot according to a colorscale associated to the total range of values. Note that this option is mutually exclusive to the labels option. Defaults to None.

  • theme (Optional[Literal['blue', 'red', 'green', 'inferno', 'fire', 'viridis', 'darkblue', 'darkgreen', 'darkred']]) –

    a color theme to use for plotting. A small set of predefined themes are provided which have relatively good aesthetics. Available themes are:

    • ’blue’

    • ’red’

    • ’green’

    • ’inferno’

    • ’fire’

    • ’viridis’

    • ’darkblue’

    • ’darkred’

    • ’darkgreen’.

    Defaults to None.

  • cmap (str) – the name of a matplotlib colormap to use for coloring or shading points. If no labels or values are passed this will be used for shading points according to density (largely only of relevance for very large datasets). If values are passed this will be used for shading according the value. Note that if theme is passed then this value will be overridden by the corresponding option of the theme. Defaults to “Blues”.

  • color_key (Union[dict, list, None]) – a way to assign colors to categoricals. This can either be an explicit dict mapping labels to colors (as strings of form ‘#RRGGBB’), or an array like object providing one color for each distinct category being provided in labels. Either way this mapping will be used to color points according to the label. Note that if theme is passed then this value will be overridden by the corresponding option of the theme. Defaults to None.

  • color_key_cmap (str) – the name of a matplotlib colormap to use for categorical coloring. If an explicit color_key is not given a color mapping for categories can be generated from the label list and selecting a matching list of colors from the given colormap. Note that if theme is passed then this value will be overridden by the corresponding option of the theme. Defaults to “Spectral”.

  • background (str) – the color of the background. Usually this will be either ‘white’ or ‘black’, but any color name will work. Ideally one wants to match this appropriately to the colors being used for points etc. This is one of the things that themes handle for you. Note that if theme is passed then this value will be overridden by the corresponding option of the theme. Defaults to “black”.

  • figsize (tuple) – the desired size of the figure. Defaults to (6, 4).

  • ax (Optional[Axes]) – the axis on which the subplot would be shown. If set to be None, a new axis would be created. Defaults to None.

  • save_show_or_return (Literal['save', 'show', 'return']) – whether to save, show or return the figure. Defaults to “return”.

  • save_kwargs (dict) –

    a dictionary that will be passed to the save_show_ret function. By default, it is an empty dictionary and the save_show_ret function will use the

    {

    “path”: None, “prefix”: ‘connectivity_base’, “dpi”: None, “ext”: ‘pdf’, “transparent”: True, “close”: True, “verbose”: True

    }

    as its parameters. Otherwise you can provide a dictionary that properly modify those keys according to your needs. Defaults to {}.

Raises:

TypeError – wrong type of x and y.

Return type:

Optional[Figure]

Returns:

The matplotlib axis with the plotted knn graph by default. If save_show_or_return is set to be “show” or “save”, nothing would be returned.