cellrank.pl.graph(data, graph_key=None, ixs=None, layout='umap', keys=('incoming', ), keylocs='uns', node_size=400, labels=None, top_n_edges=None, self_loops=True, self_loop_radius_frac=None, filter_edges=None, edge_reductions=<function sum>, edge_reductions_restrict_to_ixs=None, edge_weight_scale=10, edge_width_limit=None, edge_alpha=1.0, edge_normalize=False, edge_use_curved=True, arrows=True, font_size=12, font_color='black', color_nodes=True, cat_cmap=<matplotlib.colors.ListedColormap object>, cont_cmap=<matplotlib.colors.ListedColormap object>, legend_loc='best', title=None, figsize=None, dpi=None, save=None, layout_kwargs=mappingproxy({}))[source]

Plot a graph, visualizing incoming and outgoing edges or self-transitions.

This is a utility function to look in more detail at the transition matrix in areas of interest, e.g. around an endpoint of development. This function is meant to visualise a small subset of nodes (~100-500) and the most likely transitions between them. Note that limiting edges visualized using top_n_edges will speed things up, as well as reduce the visual clutter.

  • data (Union[~AnnData, ndarray, spmatrix]) – The graph data to be plotted.

  • graph_key (Optional[str]) – Key in adata.obsp or adata.uns where the graph is stored. Only used when data is Anndata object.

  • ixs (Union[range, array, None]) – Subset of indices of the graph to visualize.

  • layout (Union[str, Dict, Callable]) –

    Layout to use for graph drawing.

    • If str, search for embedding in adata.obsm['X_{layout}']. Use layout_kwargs={'components': [0, 1]} to select components.

    • If dict, keys should be values in interval [0, len(ixs)) and values (x, y) pairs corresponding to node positions.

  • keys (Sequence[str]) –

    Keys in adata.obs, adata.obsm or adata.obsp to color the nodes.

    • If ‘incoming’, ‘outgoing’ or ‘self_loops’, visualize reduction (see edge_reductions) for each node based on incoming or outgoing edges, respectively.

  • keylocs (Union[str, Sequence[str]]) – Locations of keys. Can be any attribute of data if it’s anndata.AnnData object.

  • node_size (float) – Size of the nodes.

  • labels (Union[Sequence[str], Sequence[Sequence[str]], None]) – Labels of the nodes.

  • top_n_edges (Union[int, Tuple[int, bool, str], None]) – Either top N outgoing edges in descending order or a tuple (top_n_edges, in_ascending_order, {'incoming', 'outgoing'}). If None, show all edges.

  • self_loops (bool) – Whether visualize self transitions and also to consider them in top_n_edges.

  • self_loop_radius_frac (Optional[float]) – Fraction of a unit circle to visualize self transitions. If None, use node_size / 1000.

  • filter_edges (Optional[Tuple[float, float]]) – Whether to remove all edges not in [min, max] interval.

  • edge_reductions (Union[Callable, Sequence[Callable]]) – Aggregation function to use when coloring nodes by edge weights.

  • edge_reductions_restrict_to_ixs (Union[range, ndarray, None]) – Whether to use the full graph when calculating the edge_reductions or just use the nodes marked by the ixs and this parameter. If None, it’s the same as ixs.

  • edge_weight_scale (float) – Number by which to scale the width of the edges. Useful when the weights are small.

  • edge_width_limit (Optional[float]) – Upper bound for the width of the edges. Useful when weights are unevenly distributed.

  • edge_alpha (float) – Alpha channel value for edges and arrows.

  • edge_normalize (bool) – If True, normalize edges to [0, 1] interval prior to applying any scaling or truncation.

  • edge_use_curved (bool) – If True, use curved edges. This can improve visualization at a small performance cost.

  • arrows (bool) – Whether to show the arrows. Setting this to False may dramatically speed things up.

  • font_size (int) – Font size for node labels.

  • font_color (str) – Label color of the nodes.

  • color_nodes (bool) – Whether to color the nodes

  • cat_cmap (ListedColormap) – Categorical colormap used when keys contain categorical variables.

  • cont_cmap (ListedColormap) – Continuous colormap used when keys contain continuous variables.

  • legend_loc (Optional[str]) – Location of the legend.

  • title (Union[str, Sequence[Optional[str]], None]) – Title of the figure(s), one for each key.

  • figsize (Optional[Tuple[float, float]]) – Size of the figure.

  • dpi (Optional[int]) – Dots per inch.

  • save (Union[Path, str, None]) – Filename where to save the plot.

  • layout_kwargs (Dict) – Additional kwargs for layout.


Nothing, just plots the figure. Optionally saves it based on save.

Return type