0

假设我有一个 ipycytoscape 图如下:

railnet= '''{
    "nodes": [
        {"data": { "id": "BER", "label":"HBf BER", "classes":"east"}},
        {"data": { "id": "MUN", "label":"HBf MUN", "classes":"west"}},
        {"data": { "id": "FRA", "label":"HBf FRA", "classes":"west"}}
        ],
    "edges": [
        {"data": { "id": "line1", "source": "BER", "target": "MUN","label":"200km/h"}},
        {"data": { "id": "line2", "source": "MUN", "target": "FRA","label":"200km/h"}},
        {"data": { "id": "line3", "source": "FRA", "target": "BER","label":"250km/h" }}           
    ]
  }'''

railnetJSON = json.loads(railnet)
ipycytoscape_obj3 = ipycytoscape.CytoscapeWidget()
ipycytoscape_obj3.graph.add_graph_from_json(railnetJSON, directed=False) # I am telling I dont want directions
ipycytoscape_obj3

如何轻松访问具有 id 的节点?

这不起作用:

ipycytoscape_obj3.graph.nodes['BER']. # --> wrong
4

1 回答 1

1

这是因为id信息在数据内部。我没有测试它,但也许nodes['data']['BER']会工作?您可以查看此示例以了解更复杂的边缘/节点交互。检查此笔记本上的 Pandas 会话。和往常一样,随时在 repo 上打开一个问题。谢谢!

于 2021-07-27T08:49:08.213 回答