I am trying to export a graph file with some visualization specifications . I could not figure out how to add multi-level attributes .
Import networkx as nx
#Create the Graph
g = nx.Graph()
g.add_edge('Andre', 'Beverly')
g.add_edge('Andre', 'Diane')
g.add_edge('Andre', 'Carol')
g.add_edge('Andre', 'Fernando')
g.add_edge('Beverly', 'Diane')
nx.draw(g)
Add attributes to the nodes
what I would like to do is to add position but using a specific attribute (names and structure)
# compute position
pos = nx.spring_layout(g)
# add attribute
g.node["Andre"]["viz"]["position"]["x"]= pos["Andre"][0]
g.node["Andre"]["viz"]["position"]["y"]= pos["Andre"][1]
this does not work
I have in fact two questions :
- how can I add a multi-level attributes
- Is there a way to do this in iterations (I could still write a function but I wonder if there is a way to do from networkx that I have not seen)
For Info : What I am really after, is a way to export network graph into a gexf file which I could open with gexf-js without passing by gephi.
P.S: I have this question and other related to this, but to my knowledge they do not address what I am after.