draw_spring#

draw_spring(G, **kwargs)[源代码]#

画出图表 G 采用弹簧布局。

这是一个便利函数,相当于::

nx.draw(G, pos=nx.spring_layout(G), **kwargs)
参数
G图表

网络X图

kwargs可选关键字

看见 draw_networkx 有关可选关键字的说明,请参见。

笔记

spring_layout is also the default layout for draw, so this function is equivalent to draw.

每次调用此函数时都会计算布局。对于重复绘制,调用 spring_layout 直接和重复使用结果::

>>> G = nx.complete_graph(5)
>>> pos = nx.spring_layout(G)
>>> nx.draw(G, pos=pos)  # Draw the original graph
>>> # Draw a subgraph, reusing the same node positions
>>> nx.draw(G.subgraph([0, 1, 2]), pos=pos, node_color="red")