如何解决使Python中的Networkx Graph动画更快
我正在计划社交网络传播。我的图由节点(10000多个节点)的大量数据组成,每个节点随着时间的推移具有2000个状态。我想用颜色说明节点的状态。
我使用的代码是一次读取每个节点的状态,所以花了这么长时间(10000个节点* 2000个状态)。有什么更好的方法可以使其更快?就像一次读取10000个节点的状态。
H = nx.read_edgelist('mydata.txt',create_using=nx.Graph(),nodetype=int)
pos = nx.spring_layout(H,iterations=200)
node_status = [[int(v) for v in line.split()] for line in open('status.txt')]
color = {0: 'blue',1: 'red'}
def status():
for n in node_status:
yield list(map(lambda x: colors[x],n))
color_map = status()
def next_status(n):
plt.cla()
c_map = next(color_map)
nx.draw(H,pos,node_color=c_map)
plt.ion()
ani = animation.FuncAnimation(plt.gcf(),next_status,interval=1000,repeat=False,frames=iter(status()))
谢谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。