Graphml output with node attributes

408 views
Skip to first unread message

psaf...@googlemail.com

unread,
Aug 27, 2010, 4:57:39 PM8/27/10
to networkx-discuss
This code throws an exception:

import networkx

g = networkx.Graph()

g.add_node(1, pos=[1,2])
g.add_node(2, pos=[2,2])
g.add_edge(1,2)

networkx.write_graphml(g, "out.graphml")

Have I done something wrong?

What I'm actually trying to do is produce output from networkx,
including node positions and colours, that I can import into Gephi.
Gephi supports a variety of formats:

http://gephi.org/users/supported-graph-formats/

But the only format also supported by networkx that allows me to
include these visualisation elements is graphml.

Peter

Aric Hagberg

unread,
Aug 27, 2010, 5:15:30 PM8/27/10
to networkx...@googlegroups.com
On Fri, Aug 27, 2010 at 2:57 PM, psaf...@googlemail.com
<psaf...@googlemail.com> wrote:
> This code throws an exception:
>
> import networkx
>
> g = networkx.Graph()
>
> g.add_node(1, pos=[1,2])
> g.add_node(2, pos=[2,2])
> g.add_edge(1,2)
>
> networkx.write_graphml(g, "out.graphml")
>
> Have I done something wrong?

The GraphML writer doesn't support writing Python lists as node data.
I don't think that type of data is in the base specification of
GraphML.

>
> What I'm actually trying to do is produce output from networkx,
> including node positions and colours, that I can import into Gephi.

> Gephi supports a variety of formats:
>
> http://gephi.org/users/supported-graph-formats/
>
> But the only format also supported by networkx that allows me to
> include these visualisation elements is graphml.

I'm not familiar with the details of Gephi but that page says that
GraphML won't work for that. Is that incorrect?
Does Gephi extend GraphML in some way?

The formats listed for "visualization attributes" are GDF and GEXF.
Those were both invented by the Gephi folks and there are currently no
NetworkX reader/writers. It might not be too hard to write them:
GEXF is XML similar to GraphML and GDF looks like a CSVish format.

If you think we should add them go ahead and open an enhancement ticket.

Aric

Stephan Gerhard

unread,
Aug 28, 2010, 9:26:29 AM8/28/10
to networkx-discuss
I'd like to help adding gexf support for reading/writing in networkx.

I created a ticket. Related discussion on the Gephi forum and a Python
parser/writer:
* http://forum.gephi.org/viewtopic.php?f=10&t=103&p=1403&hilit=python#p1403
* http://github.com/paulgirard/pygexf

Stephan
Reply all
Reply to author
Forward
0 new messages