Search code examples
pythonpython-3.xgraph-tool

How can I retrieve a selected vertex in graph-tool?


I would like to be able to retrieve the vertex_index of a currently selected vertex (the vertex currently having the mouse over it). I have not found this question asked in StackOverflow, nor this information mentioned in the official graph-tool documentation.

For example, I would like to retrieve the value "56" from this graph :

example_graph


Solution

  • As is explained in the documentation, https://graph-tool.skewed.de/static/doc/draw.html#graph_tool.draw.graph_draw, the selected vertices are returned as property map, in addition to their position:

    pos, selected = graph_draw(g)
    v = numpy.where(selected.a == True)  # get selected vertices