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=None, color_key=None, color_key_cmap=None, background='black', figsize=6, 4, ax=None, save_show_or_return='show', 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.

  • y (int) – The second component of the embedding.

  • color (str or list of str or None (default: ‘ntr’)) – Gene name(s) or cell annotation column(s)

  • basis (str or list of str (default: X)) – Which low dimensional embedding will be used to visualize the cell.

  • layer (str or list of str (default: X)) – The layers of data to represent the gene expression level.

  • highlights (list, list of list or None (default: None)) – The list that cells will be restricted to.

  • save_show_or_return ({‘show’, ‘save’, ‘return’} (default: return)) – Whether to save, show or return the figure.

  • save_kwargs (dict (default: {})) – A dictionary that will passed to the save_fig function. By default it is an empty dictionary and the save_fig function will use the {“path”: None, “prefix”: ‘nneighbors’, “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.

  • x – The first component of the embedding.

  • y – The second component of the embedding.

  • pd.DataFrame (edge_df) – The dataframe denotes the graph edge pairs. The three columns include ‘source’, ‘target’ and ‘weight’.

  • highlights – The list that cells will be restricted to.

  • edge_bundling (string or None (optional, default None)) – The edge bundling method to use. Currently supported are None or ‘hammer’. See the datashader docs on graph visualization for more details.

  • edge_cmap (string (default 'gray_r')) – 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.

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

  • labels (array, shape (n_samples,) (optional, default None)) – 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.

  • values (array, shape (n_samples,) (optional, default None)) – 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.

  • theme (string (optional, default None)) –

    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’

  • cmap (string (optional, default 'Blues')) – 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.

  • color_key (dict or array, shape (n_categories) (optional, default 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.

  • color_key_cmap (string (optional, default 'Spectral')) – 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.

  • background (string (optional, default 'white)) – 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.

  • width (int (optional, default 800)) – The desired width of the plot in pixels.

  • height (int (optional, default 800)) – The desired height of the plot in pixels

  • sort (str (optional, default raw)) – The method to reorder data so that high values points will be on top of background points. Can be one of {‘raw’, ‘abs’}, i.e. sorted by raw data or sort by absolute values.

  • save_show_or_return – Whether to save, show or return the figure.

  • save_kwargs – A dictionary that will passed to the save_fig function. By default it is an empty dictionary and the save_fig 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.

Returns

Return type

Nothing but plot the nearest neighbor graph.