I computed betweenness centralities of nodes in python igraph and saved it in csv file. Now i want to visual it in python and igraph library or gephi ,by centralities.
How can i do it?
I computed betweenness centralities of nodes in python igraph and saved it in csv file. Now i want to visual it in python and igraph library or gephi ,by centralities.
How can i do it?
Here is an example:
from igraph import *
import numpy as np
g = Graph.Famous("Zachary")
gamma = 0.33
plot(g,
vertex_color=[round(x) for x in rescale(np.array(g.betweenness())**gamma, out_range=(0, 255))],
palette=GradientPalette('Midnight Blue', 'Light Pink'),
vertex_size = 12,
bbox = (300,300))
Explanation:
Vertex colours can be specified (among other ways) as integers, representing an index into a palette. Here, I used a gradient palette between two colours. The default number of elements in a palette is 256, thus we need to generate colour indices between 0..255. The betweenness values are transformed to these with the help of the rescale
function.
Additionally, I used a power-law transformation on the betweenness values with exponent gamma
to make a smoother transition from small values (most vertices) to huge values (a few vertices).
To change the vertex area based on betweenness, you could use
plot(g,
vertex_size = (1 + np.array(g.betweenness())**0.5) * 3,
bbox = (300,300))
The exponent 0.5
ensured that it is areas rather than radii that are proportional to betweenness. Adding 1 to the values ensures a minimum vertex size.