我在可视化用python-networkx创建的图形时遇到了一些问题,我希望能够减少混乱并调节节点之间的距离(我也尝试过spring_layout,它只是以椭圆方式布局节点)。请给我建议。

部分代码:
nx.draw_networkx_edges(G, pos, edgelist=predges, edge_color='red', arrows=True)
nx.draw_networkx_edges(G, pos, edgelist=black_edges, arrows=False, style='dashed')
# label fonts
nx.draw_networkx_labels(G,pos,font_size=7,font_family='sans-serif')
nx.draw_networkx_edge_labels(G,pos,q_list,label_pos=0.3)发布于 2014-02-24 22:15:12
您的图表中有大量数据,因此将很难消除杂乱。
我建议你使用任何标准的布局。你说你用了spring_layout。我建议您再试一次,但这次在添加边时使用weight属性。
例如:
import networkx as nx
G = nx.Graph();
G.add_node('A')
G.add_node('B')
G.add_node('C')
G.add_node('D')
G.add_edge('A','B',weight=1)
G.add_edge('C','B',weight=1)
G.add_edge('B','D',weight=30)
pos = nx.spring_layout(G,scale=2)
nx.draw(G,pos,font_size=8)
plt.show()此外,还可以使用参数scale来增加节点之间的全局距离。
https://stackoverflow.com/questions/21978487
复制相似问题