Skip to content
Advertisement

networkx.exception.NetworkXError: Node 64 has no position

i am getting the error in the title, there are already some questions similar to this but none of theme seems to be working for me. this is my code in python:

JavaScript

basically, i’m trying to draw a randomGraph in NetworkX, in the code above randomGraphis a dictionary, with the keys being all the edges and the values being the array of edges each edge connects to, but when I try to run the code, it gives me the following errors:

JavaScript

Advertisement

Answer

nlist tells draw_shell which nodes to put into an inner shell and an outer shell. The source code for draw_shell is here.

Then draw_shell creates positions from the node using pos=shell_layout(G, nlist=nlist). Then it draws with nx.draw(G,pos).

The function nx.draw cannot handle drawing if the position of a node has not been defined.

In your case, you’ve put nodes 5 through 9 into one shell and 0 to 4 in another. But any node above 9 doesn’t have a position.


comment

You should always be careful when you pass an argument to a function that you’ve copied from somewhere. It’s likely that the argument’s value is important, otherwise it would have just used a default.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement