ehrapy.tools.draw_graph#
- ehrapy.tools.draw_graph(edata, *, layout='fa', init_pos=None, root=None, random_state=0, n_jobs=None, adjacency=None, key_added_ext=None, neighbors_key=None, obsp=None, copy=False, **kwds)[source]#
Force-directed graph drawing [IKM+11], [JVHB14], and [Chi18].
An alternative to tSNE that often preserves the topology of the data better. This requires to run
neighbors(), first. The default layout (‘fa’, ForceAtlas2) [JVHB14] uses the package fa2 [Chi18], which can be installed via pip install fa2. Force-directed graph drawing describes a class of long-established algorithms for visualizing graphs.- Parameters:
edata (
EHRData) – Central data object.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).init_pos (
str|bool|None, default:None) – ‘paga’/True, None/False, or any valid 2d-.obsm key. Use precomputed coordinates for initialization. If False/None (the default), initialize randomly.random_state (
int|RandomState|None, default:0) – For layouts with random initialization like ‘fr’, change this to use different intial states for the optimization. If None, no seed is set.n_jobs (
int|None, default:None) – Number of jobs for parallel computation.adjacency (
spmatrix|None, default:None) – Sparse adjacency matrix of the graph, defaults to neighbors connectivities.key_added_ext (
str|None, default:None) – By default, append layout.neighbors_key (
str|None, default:None) – If not specified, draw_graph looks .obsp[‘connectivities’] for connectivities (default storage place for pp.neighbors). If specified, draw_graph looks .obsp[.uns[neighbors_key][‘connectivities_key’]] for connectivities.obsp (
str|None, default:None) – Use .obsp[obsp] as adjacency. You can’t specify both obsp and neighbors_key at the same time.copy (
bool, default:False) – Whether to return a copy instead of writing to edata.**kwds – Parameters of chosen igraph layout. See e.g. fruchterman-reingold [FR91]. One of the most important ones is maxiter.
- Return type:
- Returns:
Depending on copy, returns or updates edata with the following field.
X_draw_graph_layout : edata.obsm Coordinates of graph layout. E.g. for layout=’fa’ (the default), the field is called ‘X_draw_graph_fa’