Note

This documents the development version of NetworkX. Documentation for the current release can be found here.

networkx.readwrite.json_graph.tree_graph

tree_graph(data, attrs={'children': 'children', 'id': 'id'})[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').

Returns
GNetworkX DiGraph

Notes

The default value of attrs will be changed in a future release of NetworkX.

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)