Skip to content

Tag: networkx

How to connect two nodes if they are disconnected

I use a python NetworkX graph. How to check if 2 nodes are disconnected and then get a new version of the graph where these 2 nodes are connected. The difference between 2 graphs should have min edit distance (Levenshtein distance) Before and after for nodes=[1,2]: | Answer you can also have a condition to ch…

How to update a NetworkX plot in real-time?

I’m trying to update a networkx plot using matplotlib in a canvas, but it adds a new plot to the graph each time instead of updating the graph below, I had to add the call to nx.draw_networkx() function to get it to update and I’m not sure if this is part of the issue. Example Code: Answer I have …

Removing self-loops from undirected networkx graph

I have created a graph from list of nodes using networkx. It has self loops. How to remove them? Following is sample: I don’t want (1, 1) edges. Answer (instructions for networkx 1.x below) If you’re using networkx 2.x try If you have a MultiGraph (which for example configuration_model produces), …