简体   繁体   中英

Import NetworkX generated GraphML data to Gephi

I am trying to import the data from a graphml file into Gephi but the attributes are not loaded properly. An example of this problem (with only one node and no edges):

<?xml version='1.0' encoding='utf-8'?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns  http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
  <key attr.name="g" attr.type="long" for="edge" id="d10" />
  <key attr.name="r" attr.type="long" for="edge" id="d9" />
  <key attr.name="b" attr.type="long" for="edge" id="d8" />
  <key attr.name="g" attr.type="long" for="node" id="d7" />
  <key attr.name="b" attr.type="long" for="node" id="d6" />
  <key attr.name="y" attr.type="double" for="node" id="d5" />
  <key attr.name="size" attr.type="double" for="node" id="d4" />
  <key attr.name="r" attr.type="long" for="node" id="d3" />
  <key attr.name="x" attr.type="double" for="node" id="d2" />
  <key attr.name="z" attr.type="double" for="node" id="d1" />
  <key attr.name="label" attr.type="string" for="node" id="d0" />
  <graph edgedefault="undirected">
    <node id="Node 1">
      <data key="d0">Node 1</data>
      <data key="d1">0.0</data>
      <data key="d2">-430.34348</data>
      <data key="d3">255</data>
      <data key="d4">10.0</data>
      <data key="d5">-32.351364</data>
      <data key="d6">0</data>
      <data key="d7">0</data>
    </node>
</graph>
</graphml>

Note: the file is generated by networkx so I do not have too much control over the order of the attributes

Once I import this file into Gephi, when I inspect the attributes I see that:

size = 4
x,y,z = (0,0,0)
r,g,b = (0,0,0)
Id = Node 1
Label = 255

If I run the same code again (and NetworkX will write the keys in different order) other other attributes will be read incorrectly)

For generating the graphml I use something like:

nodeid = 'Node 1'
G = nx.Graph()
G.add_node(nodeid)
G.node[nodeid]['label'] = nodeid
G.node[nodeid]['size'] = 4
G.node[nodeid]['x'] = -430.34348
G.node[nodeid]['y'] = -32.351364
G.node[nodeid]['z'] = 0.0
G.node[nodeid]['r'] = 255
G.node[nodeid]['g'] = 0
G.node[nodeid]['b'] = 0
nx.write_graphml(G, 'test.graphml')

Is there a way to:

1) convince Gephi to load the attributes correctly

2) convince NetworkX to write (in the graphml file) the attributes alphabetically sorted ?

确认上述问题为错误,并已在Gephi 0.9.2版本中修复。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM