Graph editor for Jupyter
Project description
Interactive Graph Editor for Jupyter
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.
Parameters
- graph (networkx.Graph): The graph object to be edited. It should be an instance of the NetworkX Graph class or a subclass.
- color_dict (Dict[str, str]): Map of color labels into HTML colors, empty by default.
Functions of buttons (from left to right)
- Select if you want to edit graph structure.
- Select if you want to edit labels.
- Select if you want for nodes to be clickable. Deselecting this should make it easier to operate on edges in a large graph.
- Select if you want for edges to be clickable. Deselecting this should make it easier to operate on nodes in a large graph.
- Turn on/off physics.
- Turn on/off fancy drawing (planar representation of a graph, works only for 3-connected planar graphs).
- Enable/disable labels.
- Exit the editor.
Mouse Functions
- 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 on the canvas.
- To delete an object, double-click on it.
Dependencies
- Jupyter notebook web environment.
- NetworkX library for graph manipulation.
Notes
This function relies on Jupyter ipywidgets, so it should work only in web versions of Jupyter. (It is possible to run editor in VSCode but it is not guaranteed that it will work properly or even run at all.)
Installation instructions
go to: https://pypi.org/project/graph-editor-jupyter/
or run:
pip install graph-editor-jupyter
Examples
Creating and editing a new graph
import networkx as nx
from graph_editor_jupyter import edit
# Create a sample graph
simple_graph = nx.Graph()
simple_graph.add_node(1)
simple_graph.add_node(2)
simple_graph.add_edge(1, 2)
# Open simple_graph in the editor
edit(simple_graph)
Labels and graph coloring
import networkx as nx
from graph_editor_jupyter import edit
labeled_graph = nx.Graph()
# Add nodes with labels (labels can be also edited and added in the editor)
labeled_graph.add_node(1, label_name='A')
labeled_graph.add_node(2, label_name='B')
labeled_graph.add_edge(1, 2)
# Add nodes with colors, label with name 'color' (additional colors can be added in the editor)
labeled_graph.add_node(3, color='c')
labeled_graph.add_node(4, color='g')
labeled_graph.add_edge(3, 4)
# Define custom colors for labels (otherwise random colors are used)
# label_colors={'color label': 'HTML color (Hex RGB or name)'}
label_colors={'c' : '#00FFFF', 'g': 'green'}
# Open labeled_graph in the editor
edit(labeled_graph, label_colors)
Displaying planar representation* of a graph
*You can use fancy drawing for 3-connected planar graphs
import networkx as nx
from graph_editor_jupyter import edit
# Create a sample planar and 3-connected graph
petersen_graph = nx.petersen_graph()
# Open petersen_graph in the editor
edit(petersen_graph)
# To display planar representation of a graph, in the editor,
# change the drawing mode to 'fancy drawing' (6th button from the left)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file graph_editor_jupyter-0.0.6.tar.gz.
File metadata
- Download URL: graph_editor_jupyter-0.0.6.tar.gz
- Upload date:
- Size: 14.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f80225d403a1100e170b3d76293960c6d0ac6f1d4d0eb67b9d223a766a212d9
|
|
| MD5 |
c15477ac1461a0c0e0dda70a5c3d2075
|
|
| BLAKE2b-256 |
63d8327304dd5319293fdac3ce5d4366bb1b13800ba3f8ec63eee8ac2dc64a93
|
File details
Details for the file graph_editor_jupyter-0.0.6-py3-none-any.whl.
File metadata
- Download URL: graph_editor_jupyter-0.0.6-py3-none-any.whl
- Upload date:
- Size: 15.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2492fb52663c80d9b4e6284700ff496570041121ebbbcb0e6ab759a728850e12
|
|
| MD5 |
c918d966d32378afebb3328803d71e87
|
|
| BLAKE2b-256 |
94cbfb25a2c63279a34a21d9ad41a2d9ddc20c35cfe1d64a5c0b2fd437766819
|