【发布时间】:2018-06-12 21:26:03
【问题描述】:
我试图通过将边缘连接到不同节点来模拟网络增长。以下代码在运行时会同时显示整个边和节点序列。 但是我如何在延迟 n 个单位时间后显示一条边被添加到另一条边(在同一张图中)。我知道我必须使用“动画”包,但不确定如何 p>
import networkx as nx
import matplotlib.pyplot as plt
def f1(g):
nodes = set([a for a, b in g] + [b for a, b in g])
G=nx.Graph()
for node in nodes:
G.add_node(node)
for edge in g:
G.add_edge(edge[0], edge[1])
pos = nx.shell_layout(G)
nx.draw(G, pos)
plt.show()
g = [(10, 11),(11, 12),(12, 13), (13, 15),(15,10)]
f1(g)
我希望意图是正确的。运行代码时,确实会显示一个图形,但是如何让每条边一个接一个地出现,而不是同时出现。
【问题讨论】:
-
您发布的代码无法运行——能否将您的问题表述为Minimal, Complete, and Verifiable example
-
我差点错过你的编辑——下次最好回复评论。如果您以
@开始您的评论,后跟用户名,该用户将在其邮箱中收到一条注释。
标签: python matplotlib animation networkx