I have two lists where the first list has the nodes and the second list has the distance between the nodes (values). How to draw a graph in Networkx using those lists?
first list:
[0, 1, 2, 3]
second list:
[0.0009, 0.3338, 0.1880, 0.3342, 0.1883, 0.1488]
My code:
dicts = {}
keys = range(4)
for i in keys:
dicts[i] = values[i]
print(dicts)
g = torch_geometric.utils.to_networkx(data, to_undirected=True)
plt.figure(len(data))
nx.draw(g, pos=dicts, with_labels=True)
plt.show()
I got this output:
{0: 0.000926, 1: 0.33381733, 2: 0.18802813, 3: 0.33418187}
NetworkXError: Node 4 has no position.