24 lines
885 B
Python
24 lines
885 B
Python
import json
|
|
import networkx as nx
|
|
from pyvis.network import Network
|
|
|
|
# 1. Load the Node-link JSON data
|
|
file_path = "graph.json" # Replace with your actual file path
|
|
with open(file_path, "r") as f:
|
|
data = json.load(f)
|
|
|
|
# 2. Reconstruct the NetworkX graph
|
|
G = nx.readwrite.json_graph.node_link_graph(data)
|
|
|
|
# 3. Initialize PyVis Network
|
|
# '100%' width/height makes it responsive. 'notebook=False' is for standalone scripts.
|
|
net = Network(height="750px", width="100%", bgcolor="#222222", font_color="white",filter_menu=True,cdn_resources="remote")
|
|
|
|
# 4. Import the NetworkX graph into PyVis
|
|
net.from_nx(G)
|
|
|
|
# 5. Enable the interactive physics/control UI panel (Optional, but great for tweaking layout)
|
|
net.show_buttons(filter_=["physics", "nodes", "edges"])
|
|
|
|
# 6. Save and open the interactive graph in your default browser
|
|
net.write_html("interactive_graph.html", open_browser=True) |