make graph visualization become colorful
Browse files- examples/graph_visual.py +5 -0
examples/graph_visual.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import networkx as nx
|
2 |
from pyvis.network import Network
|
|
|
3 |
|
4 |
# Load the GraphML file
|
5 |
G = nx.read_graphml('./dickens/graph_chunk_entity_relation.graphml')
|
@@ -10,5 +11,9 @@ net = Network(notebook=True)
|
|
10 |
# Convert NetworkX graph to Pyvis network
|
11 |
net.from_nx(G)
|
12 |
|
|
|
|
|
|
|
|
|
13 |
# Save and display the network
|
14 |
net.show('knowledge_graph.html')
|
|
|
1 |
import networkx as nx
|
2 |
from pyvis.network import Network
|
3 |
+
import random
|
4 |
|
5 |
# Load the GraphML file
|
6 |
G = nx.read_graphml('./dickens/graph_chunk_entity_relation.graphml')
|
|
|
11 |
# Convert NetworkX graph to Pyvis network
|
12 |
net.from_nx(G)
|
13 |
|
14 |
+
# Add colors to nodes
|
15 |
+
for node in net.nodes:
|
16 |
+
node['color'] = "#{:06x}".format(random.randint(0, 0xFFFFFF))
|
17 |
+
|
18 |
# Save and display the network
|
19 |
net.show('knowledge_graph.html')
|