I'm new to Qt and Netgraph, and I'd like to develop a Qt application with graph construction at its core. NetGraph's EditableGraph function meets my expectations and seems great. However, I also need to continuously update another structure based on the graph incrementally while it is constructed. For instance, I want to print the nodes and arcs of the graph as they are created.
Is it possible to retrieve the graph structure during its construction by EditableGraph and process it incrementally?
Otherwise I would have to design an interactive graph construction function with this functionality.
Accessing relevant data structures
The
EditableGraphclass (like all classes derived fromGraph) maintains several data structures to keep track of all plot elements.node_positionsmaps nodes to their (x, y) coordinates (their center),edge_pathsmaps edges to their coordinate paths,node_artists/edge_artistsmap nodes / edges to the correspondingmatplotlib.patches.PathPatchartists,node_label_artists/edge_label_artistsmap node / edge labels to the correspondingmatplotlib.text.Textinstances.The matplotlib patch artists can themselves be queried to determine their visual properties such as their color, e.g.
my_editable_graph_instance.node_artists[42].get_facecolor(). The same holds for the label artists.Update logic
The data structures are updated on key press events (insert/+ and delete/-), but to prevent race conditions, you may want to hook into draw events instead as the canvas is redrawn after all data structures are up-to-date.
Addendum:
This project may be of interest, as it uses Netgraph within a Qt application. I imagine they faced many of the same issues as you will / do.