Method to save networkx graph to json graph?

后端 未结 6 999
长发绾君心
长发绾君心 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 05:12

    Generally I use the following code :

    import networkx as nx; 
    from networkx.readwrite import json_graph;
    G = nx.Graph();
    G.add_node(...)
    G.add_edge(...)
    ....
    json_graph.node_link_data(G)
    

    it will create json formatted graph in which the nodes are in nodes and edges in links in addition to other information about the graph (directionality, ... etc)

提交回复
热议问题