def update_fig(i, args, G, pos, lineset, start_time): global counter progress = i*100/(end_time-1) text = 'Creating animation: ' update_progress(text, progress) ly1 = y1[-1] ly2 = y2[-1] ly3 = y3[-1] #only reserve 5 secs if i > start_time: #ax2.cla() if i in sorted_die_time: #clear figure ax1.cla() die_list=[] while sorted_die_time[counter] == i: die_list.append(sorted_die_node[counter]) counter += 1 for curr_node in die_list: if curr_node in args[0]: ly1 += step1 elif curr_node in args[1]: ly2 += step2 elif curr_node in args[2]: ly3 += step3 #remove the dead nodes if curr_node in G.nodes(): G.remove_node(curr_node) nodelist.discard(curr_node) ax1.set_xlim([limit[0], limit[1]]) ax1.set_ylim([limit[2], limit[3]]) ax1.set_axis_off() nx.draw_networkx_nodes(G, pos, node_size = 200, nodelist=[SINK_ID], node_color='k', ax=ax1) nx.draw_networkx_nodes(G, pos, node_size = 150, nodelist=args[0] & nodelist, node_color='b', ax=ax1) nx.draw_networkx_nodes(G, pos, node_size = 150, nodelist=args[1] & nodelist, node_color='r', ax=ax1) nx.draw_networkx_nodes(G, pos, node_size = 150, nodelist=args[2] & nodelist, node_color='g', ax=ax1) nx.draw_networkx_edges(G, pos, width=0.5, alpha=0.5, ax=ax1) lineset[0].set_data([i, i], [0, 100]) if i > 0: x=xrange(0, i+1) y1.append(ly1) y2.append(ly2) y3.append(ly3) lineset[1].set_data(x, y1) lineset[2].set_data(x, y2) lineset[3].set_data(x, y3) return ax1, lineset
imgs.append(im) lasttime = msg.timestamp elif msg.type == NET_C_DIE: if msg.node not in die_orw: die_orw[msg.node] = int(round(msg.timestamp/time_ratio)) G_orw.remove_node(msg.node) for i, group in enumerate(sets): if msg.node in group: die_ratio[i].append(die_ratio[i][-1]+step[i]) else: die_ratio[i].append(die_ratio[i][-1]) im = update_v2(G_orw, pos, sets, lineset, msg.timestamp, die_ratio) imgs.append(im) lasttime = msg.timestamp update_progress(text, currline/filesize) lasttime = int(math.ceil(lasttime)) ax3.set_xticks(xrange(0, (lasttime+1), lasttime/10)) ax3.set_xticklabels(xrange(0, (lasttime+1)/60, lasttime/600)) sorted_die_orw = sorted(die_orw.iteritems(), key=lambda (k,v): v) sorted_die_node = [k for (k,v) in sorted_die_orw] sorted_die_time = [v for (k,v) in sorted_die_orw] print sorted_die_time anim = animation.ArtistAnimation(fig,imgs, interval=500, blit=True) anim.save('orw.mp4', bitrate=4000, extra_args=['-vcodec', 'libx264']) ''' nx.draw_networkx_nodes(G, pos, node_size = 200, nodelist=[SINK_ID], node_color='k')
def update_fig(i, args, G, pos, lineset, start_time): global counter progress = i * 100 / (end_time - 1) text = 'Creating animation: ' update_progress(text, progress) ly1 = y1[-1] ly2 = y2[-1] ly3 = y3[-1] #only reserve 5 secs if i > start_time: #ax2.cla() if i in sorted_die_time: #clear figure ax1.cla() die_list = [] while sorted_die_time[counter] == i: die_list.append(sorted_die_node[counter]) counter += 1 for curr_node in die_list: if curr_node in args[0]: ly1 += step1 elif curr_node in args[1]: ly2 += step2 elif curr_node in args[2]: ly3 += step3 #remove the dead nodes if curr_node in G.nodes(): G.remove_node(curr_node) nodelist.discard(curr_node) ax1.set_xlim([limit[0], limit[1]]) ax1.set_ylim([limit[2], limit[3]]) ax1.set_axis_off() nx.draw_networkx_nodes(G, pos, node_size=200, nodelist=[SINK_ID], node_color='k', ax=ax1) nx.draw_networkx_nodes(G, pos, node_size=150, nodelist=args[0] & nodelist, node_color='b', ax=ax1) nx.draw_networkx_nodes(G, pos, node_size=150, nodelist=args[1] & nodelist, node_color='r', ax=ax1) nx.draw_networkx_nodes(G, pos, node_size=150, nodelist=args[2] & nodelist, node_color='g', ax=ax1) nx.draw_networkx_edges(G, pos, width=0.5, alpha=0.5, ax=ax1) lineset[0].set_data([i, i], [0, 100]) if i > 0: x = xrange(0, i + 1) y1.append(ly1) y2.append(ly2) y3.append(ly3) lineset[1].set_data(x, y1) lineset[2].set_data(x, y2) lineset[3].set_data(x, y3) return ax1, lineset