【发布时间】:2019-02-28 14:51:13
【问题描述】:
我正在使用 networkx 和 matplotlib 在 python 中绘制有向图。但是,并非所有边缘都是可见的。这些节点彼此如此接近,以至于没有显示两个节点之间的路径。
代码:
import networkx as nx
resultNodes = ['P0', 'P1', 'P2', 'P3', 'P4', 'P5', 'P6', 'P7', 'P8', 'P9']
resultEdges = [('P0', 'P4'), ('P0', 'P2'), ('P0', 'P1'), ('P1', 'P7'), ('P1', 'P8'),
('P1', 'P2'), ('P2', 'P3'), ('P4', 'P5'), ('P4', 'P6'), ('P5', 'P6'),
('P9', 'P2'), ('P9', 'P7'), ('P9', 'P1')]
G=nx.DiGraph()
G.add_nodes_from(resultNodes)
G.add_edges_from(resultEdges)
print("Nodes of graph: ")
print(G.nodes())
print("Edges of graph: ")
print(G.edges())
nx.draw(G,with_labels=True,font_size=15,node_color='yellowgreen',node_size=1000)
【问题讨论】:
-
resultNodes和resultEdges是什么?请参阅:How to create a Minimal, Complete, and Verifiable example。 -
不要添加到 cmets,添加到问题中!
标签: python matplotlib graph networkx