Method to save networkx graph to json graph?

后端 未结 6 880
长发绾君心
长发绾君心 2020-12-29 04:38

Seems like there should be a method in networkx to export the json graph format, but I don\'t see it. I imagine this should be easy to do with nx.to_dict_of_dicts(), but wou

6条回答
  •  生来不讨喜
    2020-12-29 04:46

    This documentation contains a full description

    A simple example is this:

    import networkx as nx
    from networkx.readwrite import json_graph
    
    DG = nx.DiGraph()
    DG.add_edge('a', 'b')
    print json_graph.dumps(DG)
    

    You can also take a look at the Javascript/SVG/D3 nice example on adding physics to the graph visualization.

提交回复
热议问题