Closed jamesbraza closed 1 month ago
The class you are looking for is called EditableGraph
. The class is intended for manual graph creation, which is why you can add edges by double-clicking on nodes (see second animation here). However, you can also use the _add_edge(self, source, target, edge_properties=None)
method directly. Depending on your environment and matplotlib parameterisation, you may need to call graph.fig.canvas.draw()
afterwards to update the figure and show the changes.
import matplotlib.pyplot as plt
from netgraph import EditableGraph
plt.ion()
graph = EditableGraph([(0, 1), (1, 2)], node_layout={0 : (0.1, 0.1), 1 : (0.9, 0.1), 2: (0.5, 0.69)}, node_labels=True)
plt.pause(3)
graph._add_edge(2, 0)
plt.pause(3)
Aside: https://stackoverflow.com/a/61459641 needs updating too I think
Thanks for the heads up. What specifically do you feel should be updated?
Aside: stackoverflow.com/a/61459641 needs updating too I think
Thanks for the heads up. What specifically do you feel should be updated?
Oh sorry for not specifying. When you run it, the netgraph.draw
interface no longer exists:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[1], line 13
10 G.add_edge('3','4')
11 G.add_edge('4','3')
---> 13 netgraph.draw(G, node_color='w', edge_color='k', edge_width=2.0, node_labels={str(ii) : str(ii) for ii in range(1,5)})
14 plt.show()
AttributeError: module 'netgraph' has no attribute 'draw'
EditableGraph._add_edge
looks great, I will investigate it! Appreciate the answer, going to close this as resolved 👍
Oh sorry for not specifying. When you run it, the netgraph.draw interface no longer exists
Good catch, thanks!
Do you offer the ability to add an edge to a
Graph
after its construction? I don't see anything in the docs for this.Aside: https://stackoverflow.com/a/61459641 needs updating too I think