drawing weighted graphs

573 views
Skip to first unread message

Bob

unread,
Dec 7, 2010, 2:18:51 PM12/7/10
to networkx-discuss
Hi All,
I tried to draw a weighted graph with the following code

nx.draw_networkx_nodes(G,pos,
node_size=110,
node_color=comms,
cmap=plt.cm.Paired)

for i in range(0, G.size()):
nx.draw_networkx_edges(G,pos,edgelist=G.edges, width = ll[i] )

it gives me an error about edges. ll is a vector containing the
weights of the edges (I have different weights for different edges).
Do you know another way to do it?

Thanks

Bob

unread,
Dec 7, 2010, 2:59:03 PM12/7/10
to networkx-discuss
the code is actually this


nx.draw_networkx_edges(G,pos,width=ll)
nx.draw_networkx_nodes(G,pos,
node_size=120,
node_color=comms,
cmap=plt.cm.Paired)

but I can only see a limited number of edges

Bob

unread,
Dec 7, 2010, 3:28:40 PM12/7/10
to networkx-discuss
I tried this

for i in range(0, len(G.edges())):
nx.draw_networkx_edges(G,pos, edgelist=G.edges()[i]), width =
G.edges(data=True)[i][2]['weight'] )

and it doesn't work..

Aric Hagberg

unread,
Dec 7, 2010, 3:40:59 PM12/7/10
to networkx...@googlegroups.com
On Tue, Dec 7, 2010 at 1:28 PM, Bob <roberto....@gmail.com> wrote:
> I tried this
>
> for i in range(0, len(G.edges())):
>        nx.draw_networkx_edges(G,pos, edgelist=G.edges()[i]), width =
> G.edges(data=True)[i][2]['weight'] )
>
> and it doesn't work..

Try

import networkx as nx
import matplotlib.pyplot as plt
G=nx.path_graph(4)
width=range(1,4)
nx.draw(G,width=width)
plt.show()

Aric

Reply all
Reply to author
Forward
0 new messages