-1

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?

Beiginner
  • 7
  • 3
  • Did you use any specific method to compute betweenness centralities of nodes in `python-igraph`? I couldn't find any but I'm able to do some visualitions using centralities of edges. – mathfux Nov 28 '21 at 19:11
  • I used g.betweenness(). with centralitiy of nodes haw can i visual the graph? – Beiginner Nov 28 '21 at 19:30
  • You might like to check out [my comment](https://stackoverflow.com/a/60147258/3044825) about issues of interactive plotting `igraph` in Python. A lot of things have changed within the last years. You are able to `pip install python-igraph` unlike in previous versions. But still, it's not sufficient to have igraph plots. You also need `pip install pycairo`. I hope this is fixed too. – mathfux Nov 28 '21 at 19:45
  • Thanks,I read your comment.i'm beginner and i don't know much about python.can you help me in ig.plot() what argumants must be placed for visualization the graph and its node's sized represent their centralities? – Beiginner Nov 28 '21 at 19:57
  • `igraph` is quite a hard thing in Python in comparison with `networkx`. It's not documented as well as `networkx`. You might also like to read [my rough notebook](https://nbviewer.org/github/loijord/Python/blob/master/graph_libraries.ipynb) of minimal working examples of `networkx` vs `igraph`. There are some examples how to plot communities (try problems F and G from `igraph` section) – mathfux Nov 28 '21 at 20:02
  • I should visualization my graph by igraph.What about gephi? – Beiginner Nov 28 '21 at 20:12
  • How can i export centralities in igraph and export it to gephi for visualization? – Beiginner Nov 28 '21 at 20:13
  • I don't have such kind of knowledge. I'm not using `gephi`. I have only a minimal working example of plotting `g.community_edge_betweenness().as_clustering()`. This is an instance of `ig.clustering.VertexClustering` class. That's all I can help you because I'm not sure how to plot communities by `g.betweenness()` which is a single list. Might other more experienced OPs can help you? – mathfux Nov 28 '21 at 20:19
  • 1
    @mathfux _"igraph is quite a hard thing in Python in comparison with networkx. It's not documented as well as networkx."_ Contributions to igraph documentation would be quite welcome. – Szabolcs Nov 29 '21 at 10:28

1 Answers1

0

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.

Szabolcs
  • 24,728
  • 9
  • 85
  • 174