paulbrodersen / netgraph

Publication-quality network visualisations in python
GNU General Public License v3.0
667 stars 40 forks source link

ValueError when trying to plot #55

Closed alfasst closed 1 year ago

alfasst commented 1 year ago

Python version: 3.10.6 netgraph version: 4.10.2

I have a network g, and I have created a pos dict using a networkx layout function. The output for the list of nodes and pos print are: print(list(g.nodes)) gives ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] print(pos) gives

{0: array([1.0000000e+00, 1.4702742e-08]),
 1: array([0.809017  , 0.58778526]),
 2: array([0.30901698, 0.95105655]),
 3: array([-0.30901702,  0.95105649]),
 4: array([-0.80901699,  0.58778526]),
 5: array([-9.99999988e-01, -7.27200340e-08]),
 6: array([-0.80901693, -0.58778529]),
 7: array([-0.30901711, -0.95105646]),
 8: array([ 0.30901713, -0.95105646]),
 9: array([ 0.80901694, -0.58778529])}

When I try to plot the network using netgraph, I get the following error: Graph(g, node_layout=pos, node_edge_width=1, edge_alpha=1, edge_width=1)

ValueError: node_layout is incomplete. The following elements are missing:
-4
-2
-8
-1
-6
-3
-7
-9
-0
-5

I don't understand the problem. My pos dict has all node positions.

Edit: I found the reason when this happens. It happens when the network is taken from a gml file. i have reproduced the issue here: https://colab.research.google.com/drive/1zhe68opt4NlF4BPVc8L1GcdRVdCCbH--

alfasst commented 1 year ago

I found the error. When reading the saved gml file, the labels are strings. so I had to do, g = nx.read_gml('netw.gml', label='id') to get rid of the error

paulbrodersen commented 1 year ago

Hi, thanks for raising the issue (and debugging it yourself!). This made me realise that the error message needs improvement. The minus signs to indicate the enumeration are confusing at best, and strings should be represented as such. I will work on that.