节点数据可用作每个节点的 Python 字典。这是一个显示 GEXF 节点即数据如何存储和操作的示例。
In [1]: import sys
In [2]: import urllib2
In [3]: import networkx as nx
In [4]: data = urllib2.urlopen('http://gexf.net/data/viz.gexf')
In [5]: G = nx.read_gexf(data)
In [6]: print G.node['a']
{'viz': {'color': {'a': 0.6, 'r': 239, 'b': 66, 'g': 173}, 'position': {'y': 40.109245, 'x': 15.783598, 'z': 0.0}, 'size': 2.0375757}, 'label': 'glossy'}
In [7]: G.node['a']['viz']['position']['x']=10
In [8]: G.node['a']['viz']['position']['y']=20
In [9]: print G.node['a']
{'viz': {'color': {'a': 0.6, 'r': 239, 'b': 66, 'g': 173}, 'position': {'y': 20, 'x': 10, 'z': 0.0}, 'size': 2.0375757}, 'label': 'glossy'}
In [10]: nx.write_gexf(G,sys.stdout)
<?xml version="1.0" encoding="utf-8"?><gexf xmlns:ns0="http://www.gexf.net/1.1draft/viz" 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="undirected" mode="static">
<nodes>
<node id="a" label="glossy">
<ns0:color b="66" g="173" r="239" />
<ns0:size value="2.0375757" />
<ns0:position x="10" y="20" z="0.0" />
</node>
</nodes>
<edges />
</graph>
</gexf>