Colouring Clusters – Python

The Graph file

*Vertices 5
1 "Jose"
2 "ShaNayNay"
3 "Watermelondrea"
4 "Barbeesha"
5 "Rieenanay"
1 5
3 4
2 4

The Python bit

# find the clusters and color them each in different colours.
from igraph import *

# read the graph
g_main = Graph.Read('',format='pajek')

# get cluster membership for each vertice
g_main.vs['cluster'] = g_main.clusters().membership

# the color scheme
list_color_scheme = ['red','purple','blue']

# list of colors for each vertice
list_g_color = []
for v in g_main.vs['cluster']:

# applies colors to each vector
g_main.vs['color'] = list_g_color

# plot it

The Graph


One reply on “Colouring Clusters – Python”

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s