如何解决使用更新的数据在同一图中为节点颜色设置动画
我使用节点和边文件创建了一个网络图。使用另一个代码每 10 秒更改一次节点文件,并且边缘文件是静态的。 用于使用带有绘图代码的更新的 I 波段客户端套接字代码进行绘图。
但问题是每当服务器向客户端发送更新的文件时,就会显示新的绘图图。这就是为什么在我的屏幕上显示 N 个绘图图形的原因。 而且我想根据同一个图中的节点状态仅对节点颜色进行动画处理。 What tool to draw an animated network graph
客户端代码-
if len(text2) < 30:
if CL[0] == "get":
for i in range(20):
BigC = open("Received-" + CL[1],"wb")
d = 0
try:
# number of paclets
CountC,countaddress = s.recvfrom(4096)
except ConnectionResetError:
print(
"Error. Port numbers not matching.")
sys.exit()
except:
print("Timeout or some other error")
sys.exit()
tillC = CountC.decode('utf8')
tillCC = int(tillC)
#print("Receiving packets will start Now if file exists.")
# print(
# "Timeout is 15 seconds so please wait for timeout at the end.")
while tillCC != 0:
ClientBData,clientbAddr = s.recvfrom(4096)
dataS = BigC.write(ClientBData)
d += 1
print("Received packet number:" + str(d))
tillCC = tillCC - 1
#BigC.close()
print(
"Check contents in your directory.")
os.system('python3 plotting.py &')
time.sleep(3)
绘制代码 -
fig = plt.figure()
net = fig.add_subplot(111)
def init_func():
with open("fileName",'r') as nodecsv:
nodereader = csv.reader(nodecsv)
nodes = [n for n in nodereader][1:]
node_names = [n[0] for n in nodes]
with open("fileName",'r') as edgecsv:
edgereader = csv.reader(edgecsv)
edges = [tuple(e) for e in edgereader][1:]
g = nx.Graph()
g.add_nodes_from(node_names)
g.add_edges_from(edges)
node_status = {}
for node in nodes:
if random.choice([True,False]):
node_status[node[0]] = node[1]
else:
node_status[node[0]] = 'R'
nx.set_node_attributes(g,node_status,'node_status')
********** other coding***********
plt.clf()
plt.cla()
ax = plt.gca()
ax.set_title('Graph')
global pos
pos = nx.fruchterman_reingold_layout(g)
nx.draw(g,pos=pos,node_size=node_size,node_color=color_map,linewidths=2,**options)
def update(it):
***************Same as above**************
nx.draw(g,**options)
ani = animation.FuncAnimation(fig,update,init_func=init_func,interval=1000)
plt.show()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。