Categories
Uncategorized

Colouring Clusters – Python

The Graph file

*Vertices 5
1 "Jose"
2 "ShaNayNay"
3 "Watermelondrea"
4 "Barbeesha"
5 "Rieenanay"
*Edges
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('clusters.net',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']:
    list_g_color.append(list_color_scheme[v])

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

# plot it
plot(g_main)

The Graph

graph

One reply on “Colouring Clusters – Python”

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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