Trying to separate dimensions of my xyz coordinates nodes to a 3D NetworkX graph

110 views
Skip to first unread message

Zac v

unread,
Dec 28, 2021, 9:40:08 AM12/28/21
to networkx-discuss
Hello everyone !

I am new to Python and I try to make a 3D network graph using a csv file, with NetworkX and Plotly, I use Spring3D function and try to separate dimensions from the array wich was generated like in a tutorial i saw on Deepnote, but I am unable to do it probably because my nodes data arent read like integers, however i specified the nodetype int in my arguments... or maybe because i have to convert my data to matrix or array...(see my screens below), when I call one of my nodes it sends me back a Key Error, but it works when i call it like string spring_3D ['4'] , i dont know if this problem is linked to the fact that i can't assign my coordinates to my nodes but i suppose... I really don't know and i tried so many ways (like using different way of import my data with csv.reader and with open i was able to see my nodes like an integer with this method np.array([[int(e) for e in row] for row in csv.reader(f, delimiter=',')]) but it didnt work at the next step. I alos try to add nodes manually but unsucessfully... I even replace Num_nodes by G and i got Key error [1] I use the read.adjlist method but it s probably the same thing...I think the answer is probably pretty obvious... IS there someone who could help me to resolve this issue, even with a completely different approach, I will be gratefull Thanks in advance !

I work on python 3.6 with Jupyter notebook and Anaconda

Screenshot 2021-12-28 at 05.14.25.png

seth....@gmail.com

unread,
Jan 3, 2022, 12:13:32 PM1/3/22
to networkx-discuss
Hello Zac,

It would really help us if you could also post how you are reading in the data to create the graph and maybe how to the csv file looks like?

If the csv file looks like

2,3
3,4
5,6

You can use pandas to read in the data and then create the networkx graph.

import pandas as pd
import networkx as nx

df = pd.read_csv('test.csv', names=['u', 'v'])
G = nx.from_pandas_edgelist(df, source='u', target='v')

Best,
Mridul
Reply all
Reply to author
Forward
0 new messages