George
unread,Jul 1, 2010, 5:28:01 PM7/1/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to networkx-discuss
Hi, I'm new to networkx and python. The following code doesn't work:
# test.py
#
import networkx as nx
import matplotlib.pyplot as plt
import random as rd
G = nx.MultiDiGraph()
for i in range(10):
G.add_node(i)
G.add_edge(rd.randint(0,9),rd.randint(0,9))
G[i]['value'] = rd.random()
nx.draw(G,node_color=[rd.random() for _ in range(10)])
plt.show()
#
#
I get the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "test.py", line 14, in <module>
nx.draw(G,node_color=[rd.random() for _ in range(10)])
File "/usr/local/lib/python2.6/dist-packages/networkx-1.2.dev-
py2.6.egg/networkx/drawing/nx_pylab.py", line 138, in draw
draw_networkx(G,pos=pos,ax=ax,**kwds)
File "/usr/local/lib/python2.6/dist-packages/networkx-1.2.dev-
py2.6.egg/networkx/drawing/nx_pylab.py", line 270, in draw_networkx
pos=nx.drawing.spring_layout(G) # default to spring layout
File "/usr/local/lib/python2.6/dist-packages/networkx-1.2.dev-
py2.6.egg/networkx/drawing/layout.py", line 211, in
fruchterman_reingold_layout
A=nx.to_numpy_matrix(G)
File "/usr/local/lib/python2.6/dist-packages/networkx-1.2.dev-
py2.6.egg/networkx/convert.py", line 651, in to_numpy_matrix
for u,v,attrs in G.edges_iter(data=True):
File "/usr/local/lib/python2.6/dist-packages/networkx-1.2.dev-
py2.6.egg/networkx/classes/multidigraph.py", line 387, in edges_iter
for key,data in keydict.iteritems():
AttributeError: 'float' object has no attribute 'iteritems'
The problem is with the attribute ['value']. If I remove it the code
works. How can I draw the network and at the same time have nodes with
attributes?
Thanks,
George.