如何将图形存储为networkx.classes.graph.Graph对象?

时间:2017-09-17 13:01:34

标签: python networkx

我对Networkx很新,所以我正在尝试各种图形函数,并希望将生成的图形存储为networkx.classes.graph.Graph对象以供进一步处理,格式为{{ 1}}出现在Python输出中。

假设我使用以下代码生成二分图:

<networkx.classes.graph.Graph at xxxxxxxxxxxxxx>

最后两行代码将生成此图: enter image description here

但是,这不是import networkx as nx import matplotlib.pyplot as plt G1 = nx.Graph() G1.add_edges_from([('Frida','The Shawshank Redemption'), ('Pablo','The Shawshank Redemption'), ('Vincent','The Shawshank Redemption'), ('Joan', 'Forrest Gump'), ('Lee', 'Forrest Gump'), ('Andy', 'The Matrix'), ('Frida', 'The Matrix'), ('Pablo', 'The Matrix'), ('Andy', 'Anaconda'), ('Claude', 'Anaconda'), ('Georgia', 'Anaconda'), ('Frida', 'The Social Network'), ('Vincent', 'The Social Network'), ('Vincent', 'The Godfather'), ('Claude', 'Monty Python and the Holy Grail'), ('Georgia', 'Monty Python and the Holy Grail'), ('Claude', 'Snakes on a Plane'), ('Georgia', 'Snakes on a Plane'), ('Joan', 'Kung Fu Panda'), ('Lee', 'Kung Fu Panda'), ('Pablo', 'The Dark Knight'), ('Andy', 'Mean Girls'), ('Joan', 'Mean Girls'), ('Lee', 'Mean Girls')]) l, r = nx.bipartite.sets(G1) pos = {} # Update position for node from each group pos.update((node, (1, index)) for index, node in enumerate(l)) pos.update((node, (2, index)) for index, node in enumerate(r)) nx.draw(G1, pos=pos, with_labels=True) plt.show() 对象。

如何将图形输出保存为networkx.classes.graph.Graph对象,以便Python可以读取此对象(并且能够检索节点和边的数量以及此类对象的其他属性)?

谢谢。

0 个答案:

没有答案