Re: [networkx-discuss] Exporting dynamic graphs to .gexf?

421 views
Skip to first unread message

Aric Hagberg

unread,
Sep 11, 2012, 11:38:16 PM9/11/12
to networkx...@googlegroups.com
On Tue, Sep 11, 2012 at 9:15 PM, ryan compton <compto...@gmail.com> wrote:
> Does anyone have some simple code that shows how to write a dynamic .gexf
> file from a networkx graph? I can't seem to find any documentation on this.
>
> For my first guess I tried:
>
> import networkx as nx
>
> G=nx.Graph()
>
> vert_attributes = {'start':0,'end':1}
> G.add_node("one",vert_attributes)
> G.add_node("two",vert_attributes)
> G.add_node("three",vert_attributes)
>
> edge_attributes = {'start':0, 'end':2}
> edge_attributes1 = {'start':1, 'end':2}
>
> G.add_edge("one", "two", attr_dict=edge_attributes)
> G.add_edge("one", "three", attr_dict=edge_attributes1)
>
> nx.write_gexf(G, "test_graph.gexf")

I doubt that the NetworkX GEXF reader and writer work well with all
possible dynamic graph formats. You could try reading the file at
http://gexf.net/data/dynamics.gexf
and see how that is represented in NetworkX.

There is also another project at https://github.com/paulgirard/pygexf
that might be helpful.

Aric

ryan compton

unread,
Sep 12, 2012, 1:43:01 PM9/12/12
to networkx...@googlegroups.com
Yes, that file has everything I want to do dynamically, but networkx seems to have trouble reading/writing that file.

This code will produce a .gexf file which Gephi can't work with:
G=nx.read_gexf("/home/ryan/Documents/dynamics.gexf")
nx.write_gexf(G,"/home/ryan/Documents/dynamics_out.gexf")

The output file looks like:
<?xml version="1.0" encoding="utf-8"?><gexf version="1.1" xmlns="http://www.gexf.net/1.1draft" xmlns:viz="http://www.gexf.net/1.1draft/viz" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/2001/XMLSchema-instance">
<graph defaultedgetype="directed" mode="static">
<attributes class="edge" mode="dynamic">
<attribute id="5" title="start" type="string" />
<attribute id="6" title="end" type="string" />
</attributes>
<attributes class="node" mode="dynamic">
<attribute id="1" title="url" type="string" />
<attribute id="2" title="indegree" type="string" />
<attribute id="3" title="start" type="string" />
</attributes>
<attributes class="node" mode="static">
<attribute id="0" title="indegree" type="string" />
<attribute id="4" title="frog" type="boolean">
<default>True</default>
</attribute>
</attributes>
<nodes>
<node id="1" label="Network">
<attvalues>
<attvalue end="2009-03-01" for="0" start="None" value="1.0" />
<attvalue end="2009-03-10" for="0" start="2009-03-01" value="2.0" />
<attvalue end="None" for="0" start="2009-03-10" value="1.0" />
</attvalues>
</node>
<node id="0" label="Gephi">
<attvalues>
<attvalue for="1" value="http://gephi.org" />
<attvalue end="None" for="2" start="None" value="1.0" />
<attvalue for="3" value="2009-03-01" />
</attvalues>
</node>
<node id="3" label="Graph">
<attvalues>
<attvalue end="2009-03-01" for="0" start="None" value="0.0" />
<attvalue end="None" for="0" start="2009-03-01" value="1.0" />
<attvalue for="4" value="False" />
</attvalues>
</node>
<node id="2" label="Visualization">
<spells>
<spell end="2009-03-01" start="None" />
<spell end="2009-03-10" start="2009-03-05" />
</spells>
<attvalues>
<attvalue end="2009-03-01" for="0" start="None" value="0.0" />
<attvalue end="None" for="0" start="2009-03-01" value="1.0" />
</attvalues>
</node>
</nodes>
<edges>
<edge id="2" source="1" target="0">
<attvalues>
<attvalue for="5" value="2009-03-01" />
</attvalues>
</edge>
<edge id="0" source="0" target="1">
<attvalues>
<attvalue for="5" value="2009-03-01" />
</attvalues>
</edge>
<edge id="4" source="0" target="3">
<attvalues>
<attvalue for="5" value="2009-03-01" />
</attvalues>
</edge>
<edge id="1" source="0" target="2">
<attvalues>
<attvalue for="5" value="2009-03-01" />
<attvalue for="6" value="2009-03-10" />
</attvalues>
</edge>
<edge id="3" source="2" target="1">
<attvalues>
<attvalue for="6" value="2009-03-10" />
</attvalues>
</edge>
</edges>
</graph>
</gexf>

Aric Hagberg

unread,
Sep 12, 2012, 1:52:10 PM9/12/12
to networkx...@googlegroups.com
I haven't looked at this in a while but the last time I did the spec
was somewhat confusing and it was clear we hadn't implemented all of
it for dynamic graphs. If you can point us to the missing or
incorrect parts we can work on fixing it. The best way is to open an
issue at https://github.com/networkx/networkx/issues

Aric
Reply all
Reply to author
Forward
0 new messages