From 1b45fe26c701962274cc2a1b2129e6a581ea79c3 Mon Sep 17 00:00:00 2001 From: nongbin Date: Sun, 20 Oct 2024 21:17:09 +0800 Subject: [PATCH] make graph visualization become colorful --- examples/graph_visual.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/graph_visual.py b/examples/graph_visual.py index 72c72bad..b455e6de 100644 --- a/examples/graph_visual.py +++ b/examples/graph_visual.py @@ -1,5 +1,6 @@ import networkx as nx from pyvis.network import Network +import random # Load the GraphML file G = nx.read_graphml('./dickens/graph_chunk_entity_relation.graphml') @@ -10,5 +11,9 @@ net = Network(notebook=True) # Convert NetworkX graph to Pyvis network net.from_nx(G) +# Add colors to nodes +for node in net.nodes: + node['color'] = "#{:06x}".format(random.randint(0, 0xFFFFFF)) + # Save and display the network net.show('knowledge_graph.html') \ No newline at end of file