Networkx export graph to graphml or gexf

47 views
Skip to first unread message

Semanti Basu

unread,
Jun 28, 2019, 7:27:31 PM6/28/19
to networkx-discuss
My networkx graph has python objects as nodes. Is there a way to write the graph to any standard form? I tried to use the write_gexf, read_graphml, generate_graphml and other functions. However these do not seem to correctly load the graph.

Dan Schult

unread,
Jun 28, 2019, 8:39:03 PM6/28/19
to networkx...@googlegroups.com
Actually, ;) all networkx graphs have python objects as nodes. :) (everything in python is an object)
So, you need to find a format that supports the features of YOUR python objects. 
If you create anything python-dependent in your node objects, it is unlikely that these formats can write that information.
You might consider relabeling your nodes to integers (https://networkx.github.io/documentation/stable/reference/relabel.html)
and then storing that graph in a standard format. The node object information would need to be stored another way. 


On Sat, Jun 29, 2019 at 9:27 AM Semanti Basu <renia...@gmail.com> wrote:
My networkx graph has python objects as nodes. Is there a way to write the graph to any standard form? I tried to use the write_gexf, read_graphml, generate_graphml and other functions. However these do not seem to correctly load the graph.

--
You received this message because you are subscribed to the Google Groups "networkx-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to networkx-discu...@googlegroups.com.
To post to this group, send email to networkx...@googlegroups.com.
Visit this group at https://groups.google.com/group/networkx-discuss.
To view this discussion on the web visit https://groups.google.com/d/msgid/networkx-discuss/d67ebb9b-8b27-4c5c-813d-7574d445d42f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Semanti Basu

unread,
Jul 1, 2019, 9:33:08 AM7/1/19
to networkx-discuss
Thanks Dan! If I could relabel my nodes to integers and store the node object information in a different way. But then I would not be able load a networkx graph directly using read_gexf , right? I would need a custom reader?


On Friday, June 28, 2019 at 8:39:03 PM UTC-4, Dan Schult wrote:
Actually, ;) all networkx graphs have python objects as nodes. :) (everything in python is an object)
So, you need to find a format that supports the features of YOUR python objects. 
If you create anything python-dependent in your node objects, it is unlikely that these formats can write that information.
You might consider relabeling your nodes to integers (https://networkx.github.io/documentation/stable/reference/relabel.html)
and then storing that graph in a standard format. The node object information would need to be stored another way. 


On Sat, Jun 29, 2019 at 9:27 AM Semanti Basu <renia...@gmail.com> wrote:
My networkx graph has python objects as nodes. Is there a way to write the graph to any standard form? I tried to use the write_gexf, read_graphml, generate_graphml and other functions. However these do not seem to correctly load the graph.

--
You received this message because you are subscribed to the Google Groups "networkx-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to networkx...@googlegroups.com.

Dan Schult

unread,
Jul 1, 2019, 4:14:31 PM7/1/19
to networkx...@googlegroups.com
If you just want to write the graph to a file and reload it into NetworkX, then you probably want to use Python's "pickle" library.
If you want to read it into other non-python programs, then look to markup languages like gml, graphml, etc.
Using pickle will store your python object nodes without any issues.

To unsubscribe from this group and stop receiving emails from it, send an email to networkx-discu...@googlegroups.com.

To post to this group, send email to networkx...@googlegroups.com.
Visit this group at https://groups.google.com/group/networkx-discuss.
Reply all
Reply to author
Forward
0 new messages