如何每1秒更改节点的颜色?

时间:2019-06-16 16:10:40

标签: python matplotlib networkx

每1秒,可以更改节点状态。这就是为什么我应该在程序运行期间更改节点颜色的原因。我该怎么做?

import matplotlib.pyplot as plt
import networkx as nx

nodes = [0,1,2,3]
edges = [(0,1), (1,2), (3,1), (2,3)]
nodeListA = [0,1]
nodeListB = [2,3]    

G = nx.Graph()
G.add_nodes_from(nodes)
G.add_edges_from(edges)
position = nx.circular_layout(G)

nx.draw_networkx_nodes(G,position, nodelist=nodeListA, node_color="b")
nx.draw_networkx_nodes(G,position, nodelist=nodeListB, node_color="r")

nx.draw_networkx_edges(G,position)
nx.draw_networkx_labels(G,position)

plt.show()

0 个答案:

没有答案