Exporting to GraphML after layouting

Have the following code:

write out a graphical file

import igraph as ig
… build my graph…
layout = g.layout_reingold_tilford()
ig.plot(g, PNG_FILE, layout=layout, bbox=(3000, 3000))
g.write_graphml(GRAPHML_FILE)

my necessity is then to import this GraphML file into Gephi.

With the above code the import works but the GraphML file did not save the cartesian coordinates of the graph as layouted with rt.

Is it possible to have the x,y coordinates of each vertex exported to the GraphML file?

The following is a fragment of a GraphML file as genererated by Gephi:

> <node id="11">
> <data key="label">Valjean</data>
> <data key="modularity_class">1</data>
> <data key="size">100.0</data>
> <data key="r">245</data>
> <data key="g">91</data>
> <data key="b">91</data>
> <data key="x">-87.93029</data>
> <data key="y">6.8120565</data>
> </node>
> <node id="48">
> <data key="label">Gavroche</data>
> <data key="modularity_class">8</data>
> <data key="size">61.600006</data>
> <data key="r">91</data>
> <data key="g">245</data>
> <data key="b">91</data>
> <data key="x">387.89572</data>
> <data key="y">-110.462326</data>
> </node>

while a fragment of the iGraph exported file from my graph is:

<node id="n0">
      <data key="v_name">000000</data>
      <data key="v_label">abroad, manager</data>
      <data key="v_city">NN</data>
      <data key="v_ismanager">Y</data>
    </node>
    <node id="n1">
      <data key="v_name">017130</data>
      <data key="v_label">Perlusz Riccardo</data>
      <data key="v_city">MI</data>
      <data key="v_ismanager">Y</data>
    </node>

If you store the layout as vertex attributes, they will be saved along with in the GraphML format.

g.vs['x'], g.vs['y'] = zip(*layout.coords)
1 Like

Thank you so much for your help and patience :slight_smile: iGraph is mavelous but I’m still banging my head from times to times :slight_smile:

1 Like