highlighting the shortest path in a networkx graph

Solutions on MaxInterview for highlighting the shortest path in a networkx graph by the best coders in the world

showing results for - "highlighting the shortest path in a networkx graph"
Erica
15 Apr 2016
1import matplotlib.pyplot as plt
2G = nx.karate_club_graph()
3pos = nx.spring_layout(G)
4nx.draw(G,pos,node_color='k')
5# draw path in red
6path = nx.shortest_path(G,source=14,target=16)
7path_edges = zip(path,path[1:])
8nx.draw_networkx_nodes(G,pos,nodelist=path,node_color='r')
9nx.draw_networkx_edges(G,pos,edgelist=path_edges,edge_color='r',width=10)
10plt.axis('equal')
11plt.show()
similar questions