scanpy.tl.draw_graph#
- scanpy.tl.draw_graph(adata, layout='fa', *, init_pos=None, root=None, rng=None, n_jobs=None, use=None, out=False, adjacency=None, neighbors_key=None, obsp=None, copy=False, key_added_ext=None, **kwds)[source]#
Force-directed graph drawing [Chippada, 2018, Islam et al., 2011, Jacomy et al., 2014].
An alternative to tSNE that often preserves the topology of the data better. This requires running
neighbors(), first.The default layout (‘fa’,
ForceAtlas2, Jacomy et al. [2014]) uses the packagefa2-modified[Chippada, 2018], which can be installed viapip install fa2-modified.Force-directed graph drawing describes a class of long-established algorithms for visualizing graphs. It was suggested for visualizing single-cell data by Islam et al. [2011]. Many other layouts as implemented in igraph [Csárdi and Nepusz, 2006] are available. Similar approaches have been used by Zunder et al. [2015] or Weinreb et al. [2017].
Array type support# Array type
supported
… experimentally in dask
Array✅
❌
✅
❌
- Parameters:
- adata
AnnData Annotated data matrix.
- layout
Literal['fr','drl','kk','grid_fr','lgl','rt','rt_circular','fa'] (default:'fa') ‘fa’ (
ForceAtlas2) or any valid igraph layout. Of particular interest are ‘fr’ (Fruchterman Reingold), ‘grid_fr’ (Grid Fruchterman Reingold, faster than ‘fr’), ‘kk’ (Kamadi Kawai’, slower than ‘fr’), ‘lgl’ (Large Graph, very fast), ‘drl’ (Distributed Recursive Layout, pretty fast) and ‘rt’ (Reingold Tilford tree layout).- root
int|None(default:None) Root for tree layouts.
- rng
int|integer|Sequence[int] |SeedSequence|Generator|BitGenerator|None(default:None) Random number generation to control stochasticity.
If a type:
SeedLikevalue, it’s used to seed a new random number generator; If anumpy.random.Generator,rng’s state will be directly advanced; IfNone, a non-reproducible random number generator is used. Seenumpy.random.default_rng()for more details.The default value matches legacy scanpy behavior and will change to
Nonein scanpy 2.0.Applies to layouts with random initialization like
'fr'.- init_pos
MultiAcc|str|bool|None(default:None) 'paga'/True,None/False, or a 2d.obsmentry, e.g.A.obsm['umap']. Otherstrs areresolve()d ifscanpy.settings.presetisScanpyV2Preview(e.g.'obsm.umap'), otherwise they are keys of.obsm. Use precomputed coordinates for initialization. IfFalse/None(the default), initialize randomly.- use
GraphAcc|str|None(default:None) The neighborhood graph (connectivities) to use, e.g.
A.obsp['k']aftersc.pp.neighbors(adata, out=A.obsp['k']), or any other graph.strs areresolve()d, e.g.'obsp.k'. IfNone, the oneneighbors()wrote by default.- out
MultiAcc|str|bool(default:False) Where to write the embedding. Given by an accessor, e.g.
A.obsm['fa'].strs areanndata.acc.AdAcc.resolve()d. Accompanyingunsentries are stored under the same key. IfTrue, the embedding is returned instead of written. IfFalse, it is written to.obsm['X_draw_graph_{layout}']and.uns['draw_graph'](.obsm['graph_{layout}']and.uns['graph_{layout}']ifscanpy.settings.presetisScanpyV2Preview).- adjacency
csr_array|csc_array|csr_matrix|csc_matrix|None(default:None) Deprecated since version 1.13.0: Store the graph in
.obspand passuse=A.obsp[...]instead.Sparse adjacency matrix of the graph, defaults to neighbors connectivities.
- neighbors_key
str|None(default:None) Deprecated since version 1.13.0: Use
useinstead, e.g.use=A.obsp['k_connectivities']forneighbors_key='k'.If not specified, draw_graph looks at
.obsp['connectivities']for connectivities (default storage place for pp.neighbors). If specified, draw_graph looks at.obsp[.uns[neighbors_key]['connectivities_key']]for connectivities.- obsp
str|None(default:None) Deprecated since version 1.13.0: Use
use=A.obsp[...]instead.Use
.obsp[obsp]as adjacency. You can’t specify bothobspandneighbors_keyat the same time.- copy
bool(default:False) Deprecated since version 1.13.0: Copy
adatabefore calling this function instead.Return a copy instead of writing to adata.
- key_added_ext
str|None(default:None) Replaces
layoutin the default key, i.e. writes.obsm['X_draw_graph_{key_added_ext}'].- **kwds
Parameters of chosen igraph layout. See e.g.
layout_fruchterman_reingold()[Fruchterman and Reingold, 1991]. One of the most important ones ismaxiter.
- adata
- Return type:
- Returns:
Returns the embedding if
out=True, elseNone. By default sets the following fields (seeoutfor others):adata.obsm['X_draw_graph_{layout}']numpy.ndarray(dtypefloat)Coordinates of graph layout. E.g. for
layout='fa'(the default), the field is called'X_draw_graph_fa'.adata.uns['draw_graph']:dictdraw_graphparameters.