ipyforcegraph
wraps force-graph and 3d-force-graph for data-driven views of graphs
with up to a few thousand nodes with composable behaviors.
if __name__ == "__main__" and "pyodide" in __import__("sys").modules:
%pip install -q -r requirements.txt
import json
from pathlib import Path
data = json.loads(Path("datasets/miserables.json").read_text())
from ipyforcegraph.graphs import ForceGraph
fg2 = ForceGraph()
fg2.source.nodes, fg2.source.links = data["nodes"], data["links"]
fg2
from ipyforcegraph.graphs import ForceGraph3D
fg3 = ForceGraph3D(source=fg2.source)
fg3
Each ForceGraph
has a DataFrameSource
. Some sample data in various formats are
included, while a graph of widget data can also be used as a
source.
ðĄ As shown above, multiple graphs can directly share the same
source
.
from IPython.display import JSON
JSON(data)
The simplest form has two DataFrame
-compatible structures, nodes
and links
.
from pandas import DataFrame
nodes
should contain at least an id
field of type str
or int
:
DataFrame(data["nodes"]).T
links
should contain at least source
and target
columns, and may refer to
either the id
or row index from the nodes
.
DataFrame(data["links"]).T
ðĄ Many of the graph behaviors reference
column_name
s from these fields, or can usetemplate
s to construct values from multiple fields.
These should all work in JupyterLite and on MyBinder
These don't work in JupyterLite, so are not published on ReadTheDocs ðŋ