动画的网络图显示的算法的进展算法、进展、网络图、动画

2023-09-11 04:51:32 作者:是梦终空°

我想动画的网络图形显示算法的进步。我使用NetworkX的图形创作。

从this SO回答,我想出了一个解决方案,使用 clear_ouput IPython.display 和命令 plt.pause()管理​​动画的速度。这非常适用于小图有几个节点,但是当我在一个10×10的网格实现,动画非常缓慢,降低了参数的 plt.pause()好像没有有对动画速度的任何影响。这里是一个的MME与Dijkstra算法的实施方案,其中我更新的节点的颜色在算法的每次迭代:

 进口数学
进口队列
进口随机
进口networkx为NX
进口matplotlib.pyplot为PLT
从IPython.display进口clear_output
%matplotlib在线

#绘图功能
高清get_fig(G,目前,preD):
    nColorList = []
    在G.nodes I():
        如果我==电流:nColorList.append(红)
        ELIF我== preD:nColorList.append(白)
        ELIF我== N:nColorList.append(灰色)
        ELIF node_visited [我] == 1:nColorList.append(宝蓝)
        其他:nColorList.append(浅灰蓝)
    plt.figure(figsize =(10,10))
    nx.draw_networkx(G,POS,node_color = nColorList,宽度= 2,node_size = 400,FONT_SIZE = 10)
    plt.axis('断')
    plt.show()

#图形创作
G = nx.DiGraph()
POS = {}
成本= {}
因为我在范围内(100):
    X = 1%10
    Y = math.floor(I / 10)
    POS [I] =(X,Y)
    如果我10%= 9和i + 1&LT!; 100:
       成本[(I,I + 1)] = random.randint(0,9)
       成本[(I + 1,I)= random.randint(0,9)
    如果我+ 10 ^; 100:
       成本[(I,I + 10)= random.randint(0,9)
       成本[(1 + 10,I)= random.randint(0,9)
G.add_edges_from(成本)

#算法初始化
实验室= {}
PATH = {}
node_visited = {}
N = random.randint(0,99)
SE = queue.PriorityQueue()
SE.put((0,N))
在G.nodes I():
    如果我== N:实验室[I] = 0
    其他:实验室[我] = 9999
    路径[I] =无
    node_visited [I] = 0

#算法主循环
同时不SE.empty():
    (升,j)的= SE.get()
    如果node_visited [J] == 1:继续
    node_visited [J] = 1
    因为我在G predecessors(J):
        insert_in_SE = 0
        如果实验室[I]≥成本[(I,J)] +实验研究[J]:
            实验室[I] =成本[(I,J)] +实验[j]的
            路径[i] = j的
            SE.put((实验室[I],I))
        clear_output(等待= TRUE)
        get_fig(G,J,I)
        plt.pause(0.0001)
打印(结束)
 

在理想情况下,我想显示整个动画中不超过5秒,而它目前需要几分钟即可完成算法,这表明 plt.pause(0.0001)不起作用。

在图形动画看了那么帖子(post 2 和后3 ),似乎从matplotlib动画模块可以用来解决这一点,但我一直没能成功地实现我的算法答案。后2的答案表明,使用 FuncAnimation 从matplotlib但我奋力更新办法适应我的问题而在后3回答引出一个很好的教程,类似的建议。

我的问题是如何提高的动画我的问题的速度:是否有可能安排 clear_output plt.pause( )命令更快的动画或者我应该用 FuncAnimation 从matplotlib?如果是后者,那我应该怎么定义更新功能?

实现 动态展示多种社区发现算法,这个Python库助你发现网络图的社区结构

感谢您的帮助。

修改1

 进口数学
进口队列
进口随机
进口networkx为NX
进口matplotlib.pyplot为PLT

#绘图功能
高清get_fig(G,目前,preD):
    在G.nodes I():
        如果我==电流:G.node [I] ['画'] SET_COLOR(红)
        ELIF我== preD:G.node [I] ['画'] SET_COLOR(白)
        ELIF我== N:G.node [I] ['画'] SET_COLOR(灰色)。
        ELIF node_visited [我] == 1:G.node [I] ['画'] SET_COLOR('宝蓝')
        其他:G.node [I] ['画'] SET_COLOR(浅灰蓝)。

#图形创作
G = nx.DiGraph()
POS = {}
成本= {}
因为我在范围内(100):
    X = 1%10
    Y = math.floor(I / 10)
    POS [I] =(X,Y)
    如果我10%= 9和i + 1&LT!; 100:
        成本[(I,I + 1)] = random.randint(0,9)
        成本[(I + 1,I)= random.randint(0,9)
    如果我+ 10 ^; 100:
        成本[(I,I + 10)= random.randint(0,9)
        成本[(1 + 10,I)= random.randint(0,9)
G.add_edges_from(成本)

#算法初始化
plt.figure(1,figsize =(10,10))
实验室= {}
PATH = {}
node_visited = {}
N = random.randint(0,99)
SE = queue.PriorityQueue()
SE.put((0,N))
在G.nodes I():
    如果我== N:实验室[I] = 0
    其他:实验室[我] = 9999
    路径[I] =无
    node_visited [I] = 0
    G.node [I] ['画'] = nx.draw_networkx_nodes(G,pos,nodelist=[i],node_size=400,alpha=1,with_labels=True,node_color='powderblue')
对于I,J在G.edges():
    政[i] [j]的['画'] = nx.draw_networkx_edges(G,POS,EdgeList都= [(I,J),宽度= 2)

plt.ion()
plt.draw()
plt.show()

#算法主循环
同时不SE.empty():
    (升,j)的= SE.get()
    如果node_visited [J] == 1:继续
    node_visited [J] = 1
    因为我在G predecessors(J):
        insert_in_SE = 0
        如果实验室[I]≥成本[(I,J)] +实验研究[J]:
            实验室[I] =成本[(I,J)] +实验[j]的
            路径[i] = j的
            SE.put((实验室[I],I))
        get_fig(G,J,I)
        plt.draw()
        plt.pause(0.00001)
plt.close()
 

编辑2

 进口数学
进口队列
进口随机
进口networkx为NX
进口matplotlib.pyplot为PLT

#图形创作
G = nx.DiGraph()
POS = {}
成本= {}
因为我在范围内(100):
    X = 1%10
    Y = math.floor(I / 10)
    POS [I] =(X,Y)
    如果我10%= 9和i + 1&LT!; 100:
        成本[(I,I + 1)] = random.randint(0,9)
        成本[(I + 1,I)= random.randint(0,9)
    如果我+ 10 ^; 100:
        成本[(I,I + 10)= random.randint(0,9)
        成本[(1 + 10,I)= random.randint(0,9)
G.add_edges_from(成本)

#算法初始化
实验室= {}
PATH = {}
node_visited = {}
N = random.randint(0,99)
SE = queue.PriorityQueue()
SE.put((0,N))
比照= plt.figure(1,figsize =(10,10))
AX = cf.add_axes((0,0,1,1))
在G.nodes I():
    如果我== N:
        实验室[I] = 0
        G.node [I] ['画'] = nx.draw_networkx_nodes(G,POS,节点列表= [我],node_size = 400,阿尔法= 1.0,node_color =灰色)
    其他:
        实验室[我] = 9999
        G.node [I] ['绘制'] = nx.draw_networkx_nodes(G,POS,节点列表= [I]中,node_size = 400,α-= 0.2,node_color ='宝蓝')
    路径[I] =无
    node_visited [I] = 0
对于I,J在G.edges():
    政[I] [j]的['绘制'] = nx.draw_networkx_edges(G,POS,EdgeList都= [(I,J)],宽度= 3,α-= 0.2,箭头=假)

plt.ion()
plt.show()
AX = plt.gca()
帆布= ax.figure.canvas
背景= canvas.copy_from_bbox(ax.bbox)

#算法主循环
同时不SE.empty():
    (升,j)的= SE.get()
    如果node_visited [J] == 1:继续
    node_visited [J] = 1
    如果j = N!:
        G.node [J] ['画']。SET_COLOR(R)
    因为我在G predecessors(J):
        insert_in_SE = 0
        如果实验室[I]≥成本[(I,J)] +实验研究[J]:
            实验室[I] =成本[(I,J)] +实验[j]的
            路径[i] = j的
            SE.put((实验室[I],I))
        如果我= N!
            G.node [I] ['画'。set_alpha(0.7)
            政[i] [j]的['画'。set_alpha(1.0)
        ax.draw_artist(G [i] [j]的['画'])
        ax.draw_artist(G.node [I] ['画'])
        ax.draw_artist(G.node [J] ['画'])
        canvas.blit(ax.bbox)
        plt.pause(0.0001)
plt.close()
 

解决方案

如果您的图形是不是太大了,你可以试试下面的方法,设置属性为单个节点和边缘。关键是要保存的绘图功能,让你的句柄喜欢的颜色,透明度和可视性对象属性的输出。

 进口networkx为NX
进口matplotlib.pyplot为PLT

G = nx.cycle_graph(12)
POS = nx.spring_layout(G)

比照= plt.figure(1,figsize =(8,8))
AX = cf.add_axes((0,0,1,1))

对于n在G:
    G.node [N] ['画'] = nx.draw_networkx_nodes(G,POS,节点列表= [N],with_labels =假,node_size = 200,阿尔法= 0.5,node_color ='R')
对于U,V在G.edges():
    政[U] [V] ['画'] = nx.draw_networkx_edges(G,POS,EdgeList都= [(U,V),阿尔法= 0.5,箭头​​=假,宽度= 5)

plt.ion()
plt.draw()

SP = nx.shortest_path(G,0,6)
边=拉链(SP [: -  1],SP [1:])

对于U,V在边缘:
    plt.pause(1)
    G.node [U] ['画']。SET_COLOR(R)
    G.node [V] ['画']。SET_COLOR(R)
    政[U] [V] ['画'。set_alpha(1.0)
    政[U] [V] ['画']。SET_COLOR(R)
    plt.draw()
 

修改

下面是使用的Graphviz进行布局一个10×10格的例子。 整个事情运行在我的机器上大约1秒钟。

 进口networkx为NX
进口matplotlib.pyplot为PLT

G = nx.grid_2d_graph(10,10)
POS = nx.graphviz_layout(G)

比照= plt.figure(1,figsize =(8,8))
AX = cf.add_axes((0,0,1,1))

对于n在G:
    G.node [N] ['画'] = nx.draw_networkx_nodes(G,POS,节点列表= [N],with_labels =假,node_size = 200,阿尔法= 0.5,node_color ='K')
对于U,V在G.edges():
    政[U] [V] ['画'] = nx.draw_networkx_edges(G,POS,EdgeList都= [(U,V),阿尔法= 0.5,箭头​​=假,宽度= 5)

plt.ion()
plt.draw()
plt.show()
SP = nx.shortest_path(G,(0,0),(9,9))
边=拉链(SP [: -  1],SP [1:])

对于U,V在边缘:
    G.node [U] ['画']。SET_COLOR(R)
    G.node [V] ['画']。SET_COLOR(R)
    政[U] [V] ['画'。set_alpha(1.0)
    政[U] [V] ['画']。SET_COLOR(R)
    plt.draw()
 

编辑2

下面是另一种方法,是更快(不重绘轴或所有节点),并采用了广度优先搜索算法。这一次运行在我的机器上大约2秒钟。我注意到,一些后端的速度更快 - 我使用GTKAgg

 进口networkx为NX
进口matplotlib.pyplot为PLT

高清single_source_shortest_path(G,源):
    AX = plt.gca()
    帆布= ax.figure.canvas
    背景= canvas.copy_from_bbox(ax.bbox)
    级别= 0#当前级别
    nextlevel = {来源:1}的节点#列表检查在一个新的水平
    路径= {来源:[来源]}#路径词典(路径从源键)
    G.node [来源] ['画']。SET_COLOR(R)
    G.node [来源] ['画']。set_alpha(1.0)
    而nextlevel:
        thislevel = nextlevel
        nextlevel = {}
        对于V IN thislevel:
#canvas.restore_region(背景)
            S = G.node [V] ['画']
            s.set_color(R)
            s.set_alpha('1.0')
            为瓦特G中[V]:
                当w不在路径:
                    N = G.node [W] ['画']
                    n.set_color(R)
                    n.set_alpha('1.0')
                    = G [V] [W] ['画']
                    e.set_alpha(1.0)
                    e.set_color('K')
                    ax.draw_artist(五)
                    ax.draw_artist(N)
                    ax.draw_artist(多个)
                    路径[瓦特] =路径[V] + [瓦特]
                    nextlevel [瓦特] = 1
                    canvas.blit(ax.bbox)
        水平=等级+ 1
    返回路径



如果__name __ =='__ main__:

    G = nx.grid_2d_graph(10,10)
    POS = nx.graphviz_layout(G)
    比照= plt.figure(1,figsize =(8,8))
    AX = cf.add_axes((0,0,1,1))

    对于n在G:
        G.node [N] ['画'] = nx.draw_networkx_nodes(G,POS,节点列表= [N],with_labels =假,node_size = 200,阿尔法= 0.2,node_color ='K')
    对于U,V在G.edges():
        政[U] [V] ['画'] = nx.draw_networkx_edges(G,POS,EdgeList都= [(U,V),阿尔法= 0.5,箭头​​=假,宽度= 5)
    plt.ion()
    plt.show()

    PATH = single_source_shortest_path(G,源=(0,0))
 

I would like to animate a network graph to show the progress of an algorithm. I am using NetworkX for graph creation.

From this SO answer, I came up with a solution using clear_ouput from IPython.display and the command plt.pause() to manage the speed of the animation. This works well for small graphs with a few nodes but when I implement on a 10x10 grid, the animation is very slow and reducing the argument in plt.pause() does not seem to have any effect on the animation speed. Here is a MME with an implementation of Dijkstra's algorithm where I update the colors of the nodes at each iteration of the algorithm:

import math
import queue
import random
import networkx as nx
import matplotlib.pyplot as plt
from IPython.display import clear_output
%matplotlib inline

# plotting function
def get_fig(G,current,pred): 
    nColorList = []
    for i in G.nodes():        
        if i == current: nColorList.append('red')
        elif i==pred: nColorList.append('white')
        elif i==N: nColorList.append('grey')        
        elif node_visited[i]==1:nColorList.append('dodgerblue')
        else: nColorList.append('powderblue')
    plt.figure(figsize=(10,10))
    nx.draw_networkx(G,pos,node_color=nColorList,width=2,node_size=400,font_size=10)
    plt.axis('off')
    plt.show()

# graph creation
G=nx.DiGraph()
pos={}
cost={}
for i in range(100):
    x= i % 10
    y= math.floor(i/10)
    pos[i]=(x,y)    
    if i % 10 != 9 and i+1 < 100: 
       cost[(i,i+1)] = random.randint(0,9)
       cost[(i+1,i)] = random.randint(0,9)
    if i+10 < 100: 
       cost[(i,i+10)] = random.randint(0,9)
       cost[(i+10,i)] = random.randint(0,9)
G.add_edges_from(cost)   

# algorithm initialization
lab={}
path={}
node_visited={}
N = random.randint(0,99)
SE = queue.PriorityQueue()
SE.put((0,N))
for i in G.nodes():       
    if i == N: lab[i] = 0        
    else: lab[i] = 9999
    path[i] = None
    node_visited[i] = 0 

# algorithm main loop    
while not SE.empty():
    (l,j) = SE.get()    
    if node_visited[j]==1: continue
    node_visited[j] = 1
    for i in G.predecessors(j):        
        insert_in_SE = 0               
        if lab[i] > cost[(i,j)] + lab[j]:
            lab[i] = cost[(i,j)] + lab[j]
            path[i] = j
            SE.put((lab[i],i))
        clear_output(wait=True)         
        get_fig(G,j,i)
        plt.pause(0.0001)
print('end')

Ideally I would like to show the whole animation in no more than 5 seconds, whereas it currently takes a few minutes to complete the algorithm, which suggests that plt.pause(0.0001) does not work as intended.

After reading SO posts on graph animation (post 2 and post 3), it seems that the animation module from matplotlib could be used to resolve this but I have not been able to successfully implement the answers in my algorithm. The answer in post 2 suggests the use of FuncAnimation from matplotlib but I am struggling to adapt the update method to my problem and the answer in post 3 leads to a nice tutorial with a similar suggestion.

My question is how can I improve the speed of the animation for my problem: is it possible to arrange the clear_output and plt.pause() commands for faster animation or should I use FuncAnimation from matplotlib? If it's the latter, then how should I define the update function?

Thank you for your help.

EDIT 1

import math
import queue
import random
import networkx as nx
import matplotlib.pyplot as plt

# plotting function
def get_fig(G,current,pred):   
    for i in G.nodes():        
        if i==current: G.node[i]['draw'].set_color('red')            
        elif i==pred: G.node[i]['draw'].set_color('white')
        elif i==N: G.node[i]['draw'].set_color('grey')        
        elif node_visited[i]==1: G.node[i]['draw'].set_color('dodgerblue')
        else: G.node[i]['draw'].set_color('powderblue')    

# graph creation
G=nx.DiGraph()
pos={}
cost={}
for i in range(100):
    x= i % 10
    y= math.floor(i/10)
    pos[i]=(x,y)    
    if i % 10 != 9 and i+1 < 100: 
        cost[(i,i+1)] = random.randint(0,9)
        cost[(i+1,i)] = random.randint(0,9)
    if i+10 < 100: 
        cost[(i,i+10)] = random.randint(0,9)
        cost[(i+10,i)] = random.randint(0,9)
G.add_edges_from(cost)

# algorithm initialization
plt.figure(1, figsize=(10,10))
lab={}
path={}
node_visited={}
N = random.randint(0,99)
SE = queue.PriorityQueue()
SE.put((0,N))
for i in G.nodes():       
    if i == N: lab[i] = 0        
    else: lab[i] = 9999
    path[i] = None
    node_visited[i] = 0 
    G.node[i]['draw'] = nx.draw_networkx_nodes(G,pos,nodelist=[i],node_size=400,alpha=1,with_labels=True,node_color='powderblue')
for i,j in G.edges():
    G[i][j]['draw']=nx.draw_networkx_edges(G,pos,edgelist=[(i,j)],width=2)    

plt.ion()
plt.draw()
plt.show()

# algorithm main loop  
while not SE.empty():
    (l,j) = SE.get()    
    if node_visited[j]==1: continue
    node_visited[j] = 1
    for i in G.predecessors(j):        
        insert_in_SE = 0               
        if lab[i] > cost[(i,j)] + lab[j]:
            lab[i] = cost[(i,j)] + lab[j]
            path[i] = j
            SE.put((lab[i],i))       
        get_fig(G,j,i)        
        plt.draw()
        plt.pause(0.00001)
plt.close()

EDIT 2

import math
import queue
import random
import networkx as nx
import matplotlib.pyplot as plt

# graph creation
G=nx.DiGraph()
pos={}
cost={}
for i in range(100):
    x= i % 10
    y= math.floor(i/10)
    pos[i]=(x,y)    
    if i % 10 != 9 and i+1 < 100: 
        cost[(i,i+1)] = random.randint(0,9)
        cost[(i+1,i)] = random.randint(0,9)
    if i+10 < 100: 
        cost[(i,i+10)] = random.randint(0,9)
        cost[(i+10,i)] = random.randint(0,9)
G.add_edges_from(cost)

# algorithm initialization
lab={}
path={}
node_visited={}
N = random.randint(0,99)
SE = queue.PriorityQueue()
SE.put((0,N))
cf = plt.figure(1, figsize=(10,10))    
ax = cf.add_axes((0,0,1,1))
for i in G.nodes():       
    if i == N: 
        lab[i] = 0
        G.node[i]['draw'] = nx.draw_networkx_nodes(G,pos,nodelist=[i],node_size=400,alpha=1.0,node_color='grey')
    else: 
        lab[i] = 9999
        G.node[i]['draw'] = nx.draw_networkx_nodes(G,pos,nodelist=[i],node_size=400,alpha=0.2,node_color='dodgerblue')
    path[i] = None
    node_visited[i] = 0
for i,j in G.edges():
    G[i][j]['draw']=nx.draw_networkx_edges(G,pos,edgelist=[(i,j)],width=3,alpha=0.2,arrows=False)

plt.ion()
plt.show()
ax = plt.gca()
canvas = ax.figure.canvas
background = canvas.copy_from_bbox(ax.bbox)

# algorithm main loop  
while not SE.empty():
    (l,j) = SE.get()    
    if node_visited[j]==1: continue
    node_visited[j] = 1
    if j!=N:
        G.node[j]['draw'].set_color('r')        
    for i in G.predecessors(j):        
        insert_in_SE = 0               
        if lab[i] > cost[(i,j)] + lab[j]:
            lab[i] = cost[(i,j)] + lab[j]
            path[i] = j
            SE.put((lab[i],i))
        if i!=N:            
            G.node[i]['draw'].set_alpha(0.7)
            G[i][j]['draw'].set_alpha(1.0)
        ax.draw_artist(G[i][j]['draw'])
        ax.draw_artist(G.node[i]['draw'])
        ax.draw_artist(G.node[j]['draw'])
        canvas.blit(ax.bbox)    
        plt.pause(0.0001)
plt.close()

解决方案

If your graph isn't too big you could try the following approach that sets the properties for individual nodes and edges. The trick is to save the output of the drawing functions which gives you a handle to the object properties like color, transparency, and visibility.

import networkx as nx
import matplotlib.pyplot as plt

G = nx.cycle_graph(12)
pos = nx.spring_layout(G)

cf = plt.figure(1, figsize=(8,8))
ax = cf.add_axes((0,0,1,1))

for n in G:
    G.node[n]['draw'] = nx.draw_networkx_nodes(G,pos,nodelist=[n], with_labels=False,node_size=200,alpha=0.5,node_color='r')
for u,v in G.edges():
    G[u][v]['draw']=nx.draw_networkx_edges(G,pos,edgelist=[(u,v)],alpha=0.5,arrows=False,width=5)

plt.ion()
plt.draw()

sp = nx.shortest_path(G,0,6)
edges = zip(sp[:-1],sp[1:])

for u,v in edges:
    plt.pause(1)
    G.node[u]['draw'].set_color('r')
    G.node[v]['draw'].set_color('r')
    G[u][v]['draw'].set_alpha(1.0)
    G[u][v]['draw'].set_color('r')
    plt.draw()

EDIT

Here is an example on a 10x10 grid using graphviz to do the layout. The whole thing runs in about 1 second on my machine.

import networkx as nx
import matplotlib.pyplot as plt

G = nx.grid_2d_graph(10,10)
pos = nx.graphviz_layout(G)

cf = plt.figure(1, figsize=(8,8))
ax = cf.add_axes((0,0,1,1))

for n in G:
    G.node[n]['draw'] = nx.draw_networkx_nodes(G,pos,nodelist=[n], with_labels=False,node_size=200,alpha=0.5,node_color='k')
for u,v in G.edges():
    G[u][v]['draw']=nx.draw_networkx_edges(G,pos,edgelist=[(u,v)],alpha=0.5,arrows=False,width=5)

plt.ion()
plt.draw()
plt.show()
sp = nx.shortest_path(G,(0,0),(9,9))
edges = zip(sp[:-1],sp[1:])

for u,v in edges:
    G.node[u]['draw'].set_color('r')
    G.node[v]['draw'].set_color('r')
    G[u][v]['draw'].set_alpha(1.0)
    G[u][v]['draw'].set_color('r')
    plt.draw()

EDIT 2

Here is another approach that is faster (doesn't redraw axis or all nodes) and uses a breadth first search algorithm. This one runs in about 2 seconds on my machine. I noticed that some backends are faster - I'm using GTKAgg.

import networkx as nx
import matplotlib.pyplot as plt

def single_source_shortest_path(G,source):
    ax = plt.gca()
    canvas = ax.figure.canvas
    background = canvas.copy_from_bbox(ax.bbox)
    level=0                  # the current level
    nextlevel={source:1}       # list of nodes to check at next level
    paths={source:[source]}  # paths dictionary  (paths to key from source)
    G.node[source]['draw'].set_color('r')
    G.node[source]['draw'].set_alpha('1.0')
    while nextlevel:
        thislevel=nextlevel
        nextlevel={}
        for v in thislevel:
#            canvas.restore_region(background)
            s = G.node[v]['draw']
            s.set_color('r')
            s.set_alpha('1.0')
            for w in G[v]:
                if w not in paths:
                    n = G.node[w]['draw']
                    n.set_color('r')
                    n.set_alpha('1.0')
                    e = G[v][w]['draw']
                    e.set_alpha(1.0)
                    e.set_color('k')
                    ax.draw_artist(e)
                    ax.draw_artist(n)
                    ax.draw_artist(s)
                    paths[w]=paths[v]+[w]
                    nextlevel[w]=1
                    canvas.blit(ax.bbox)
        level=level+1
    return paths



if __name__=='__main__':

    G = nx.grid_2d_graph(10,10)
    pos = nx.graphviz_layout(G)
    cf = plt.figure(1, figsize=(8,8))
    ax = cf.add_axes((0,0,1,1))

    for n in G:
        G.node[n]['draw'] = nx.draw_networkx_nodes(G,pos,nodelist=[n], with_labels=False,node_size=200,alpha=0.2,node_color='k')
    for u,v in G.edges():
        G[u][v]['draw']=nx.draw_networkx_edges(G,pos,edgelist=[(u,v)],alpha=0.5,arrows=False,width=5)
    plt.ion()
    plt.show()

    path = single_source_shortest_path(G,source=(0,0))