I'm trying to represent some numbers as edges of a graph with connected components. For this, I've been using python's networkX module.
My graph is G, and has nodes and edges initialised as follows:
G = nx.Graph()
for (x,y) in my_set:
G.add_edge(x,y)
print G.nodes() #This prints all the nodes
print G.edges() #Prints all the edges as tuples
adj_matrix = nx.to_numpy_matrix(G)
Once I add the following line,
pos = nx.spring_layout(adj_matrix)
I get the abovementioned error. If it might be useful, all the nodes are numbered in 9-15 digits. There are 412 nodes and 422 edges.
Detailed error:
File "pyjson.py", line 89, in <module>
mainevent()
File "pyjson.py", line 60, in mainevent
pos = nx.spring_layout(adj_matrix)
File "/usr/local/lib/python2.7/dist-packages/networkx/drawing/layout.py", line 244, in fruchterman_reingold_layout
A=nx.to_numpy_matrix(G,weight=weight)
File "/usr/local/lib/python2.7/dist-packages/networkx/convert_matrix.py", line 128, in to_numpy_matrix
nodelist = G.nodes()
AttributeError: 'matrix' object has no attribute 'nodes'
Edit: Solved below. Useful information: pos creates a dict with coordinates for each node. Doing nx.draw(G,pos) creates a pylab figure. But it doesn't display it, because pylab doesn't display automatically.

spring_layouttakes a graph as the first param, not a matrix arraysprint_layoutreturns the node positions, you need to pass this tonx.drawsonx.draw(G, nx.spring_layout(G))would work, I can post an example