Reputation:
I have an edge list which nodes are string values such as cities name. After applying community detection algorithm on them, i got cities with labels, that cities with same label are grouped in same community. i want to visualize the graph of cities where cities with same label get colored with same color. can any one help me with this? i dont know even pyvis has this feature or not?
i am able to draw a graph using this code:
from pyvis.network import Network
net = Network(height='800px', width='800px', directed=False, notebook=True)
net.from_nx(G)
net.show("example.html")
But i dont know how to append labels to nodes based on the communities detected.
Upvotes: 1
Views: 930
Reputation: 187
When creating your pyvis graph, you can give each community a unique color by giving each node in that community the same color. Something like:
import random
r = lambda: random.randint(0,255)
# Loop over each community
for community in graph:
communityColorString = '#%02X%02X%02X' % (r(),r(),r())
# Loop over each node
for node in community:
newGraph.add_node(word_a, word_a, title=word_a, color=communityColorString)
Upvotes: 0