1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
import numpy as np
import networkx as nx
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
G = nx.Graph()
G.add_edges_from([(0,1),(1,2),(2,0)])
fig = plt.figure(figsize=(5,5))
pos=nx.spring_layout(G)
nc =np.random.random(3) #'r' je voulais l'initialiser avec rouge mais tjr ça mache pas
nc1 =np.random.random(3)# 'g'
nc2 = np.random.random(3)#'y'
#nodes = nx.draw_networkx_nodes(G,pos)
nodess=nx.draw_networkx_nodes(G, pos,
nodelist=[0],
node_color=nc
)
nodess1=nx.draw_networkx_nodes(G, pos,
nodelist=[1],
node_color=nc1
)
nodess2=nx.draw_networkx_nodes(G, pos,
nodelist=[2],
node_color=nc2
)
edges = nx.draw_networkx_edges(G,pos)
def update(n):
nc = np.random.random(3)#['g','g','y']
nodess.set_array(nc)
return nodess,
def update1(n):
nc2 =np.random.random(3)# ['g','r','y']
nodess2.set_array(nc2)
return nodess2,
def update2(n):
nc1 = np.random.random(3) #['r','y','g'] deja ça marche pas , je veux precisier l'odre de passage je sais pas comment passer les coleur tant que liste je l'ai remplacé
#par random
nodess1.set_array(nc1)
return nodess1,
anim = FuncAnimation(fig, update, interval=2000, blit=True)
anim1 = FuncAnimation(fig, update1, interval=2000, blit=True)
anim2 = FuncAnimation(fig, update2, interval=2000, blit=True)
plt.show() |
Partager