这应该工作:
import networkx as NX
import pygraphviz as PG
G = PG.AGraph()
nlist = "A B C D E".split()
a, b = "A A B", "B C D"
elist = zip(a.split(), b.split())
G.add_nodes_from(nlist)
G.add_edges_from(elist)
G.node_attr.update(color="red", style="filled")
G.edge_attr.update(color="blue", len="2.0", width="2.0")
print(G.edge_attr)
# returns {'color': 'red', 'width': '', 'len': '2.0'}
# add new edge with custom length (all others have length=2.0):
G.add_edge("C", "E", len="3.0", color="blue", width="2.0")
edge = G.get_edge("C", "E")
print(edge_attr)
# returns {'color': 'blue', 'width': '2.0', 'len': '3.0'}
# and you can confirm that introspection by drawing & printing this graph:
G.draw('somefolderandfilename.png', format='png', prog='neato')
Run Code Online (Sandbox Code Playgroud)
大多数图形绘制算法使用某种版本的SMACOF,这当然会改变边长; 但是,如果可能的话,graphviz布局引擎'neato'(作为上面'draw'的第二个参数提供)应该保留用户设置的边长.
我在这里使用的库肯定足以处理80,000个节点.