i have built a graph with networkx, how to make it interactive so i can drag the nodes in python

Once you have built a graph using networkx, you can plot it using matplotlib or any other visualization library. To make it interactive and allow dragging of nodes, you can use the pyplot library from Matplotlib and the draw_networkx function from NetworkX.

Here's an example:

main.py
import networkx as nx
import matplotlib.pyplot as plt

# create a graph
G = nx.Graph()
G.add_edges_from([(1, 2), (1, 3), (2, 3), (3, 4), (4, 5), (4, 6), (5, 6)])

# plot the graph
pos = nx.spring_layout(G)
nx.draw_networkx(G, pos)

# make it interactive
plt.ion()
plt.show()

# allow dragging of nodes
while True:
    try:
        plt.pause(.1)
    except Tkinter.TclError:
        break
388 chars
22 lines

This will create a spring layout of the graph and plot it using draw_networkx. It will then make the plot interactive and allow you to drag the nodes around.

gistlibby LogSnag