An interactive graph editor function designed for Jupyter notebooks. edit(graph: nx.Graph)
function allows users
to manipulate a graph by creating vertices, edges, and adding labels directly within a Jupyter environment.
- graph (networkx.Graph): The graph object to be edited. It should be an instance of the NetworkX Graph class or a subclass.
- Select whether you want to edit graph structure.
- Select whether you want to edit labels.
- Toggle nodes clickable option.
- Toggle edges clickable option.
- Close editing window.
- Click and drag vertices to move them around the canvas.
- To create an edge, click on one vertex and then click on another vertex.
An edge will be created between the two selected vertices. - To create a vertex, click on empty space of a canvas.
- To delete an object, double-click on it.
- Jupyter notebook web environment.
- NetworkX library for graph manipulation.
This function relies on Jupyter ipywidgets, so it should work only in web versions of Jupyter.
import networkx as nx
from pygraphedit import edit
# Create a sample graph
G = nx.Graph()
G.add_nodes_from([1, 2, 3])
G.add_edges_from([(1, 2), (2, 3)])
# Call the interactive graph editor
edit(G)