tree_graph#

tree_graph(data, attrs=None, ident='id', children='children')[source]#

Returns graph from tree data format.

Parameters:
datadict

Tree formatted graph data

attrsdict

A dictionary that contains two keys ‘id’ and ‘children’. The corresponding values provide the attribute names for storing NetworkX-internal graph data. The values should be unique. Default value: dict(id='id', children='children').

Deprecated since version 2.6: The attrs keyword argument is replaced by ident and children and will be removed in networkx 3.0

identstring

Attribute name for storing NetworkX-internal graph data. ident must have a different value than children. The default is ‘id’.

childrenstring

Attribute name for storing NetworkX-internal graph data. children must have a different value than ident. The default is ‘children’.

Returns:
GNetworkX DiGraph

Examples

>>> from networkx.readwrite import json_graph
>>> G = nx.DiGraph([(1, 2)])
>>> data = json_graph.tree_data(G, root=1)
>>> H = json_graph.tree_graph(data)