igraph-help
[Top][All Lists]

[igraph] Color of nodes and edges according to numbers

 From: Daniele Notarmuzi Subject: [igraph] Color of nodes and edges according to numbers Date: Tue, 30 May 2017 12:34:17 +0200

Good morning,

I use python 2.7.5 on ubuntu 14.04 and python-igraph 0.6.5

I have the following problem: I have a network with N nodes and and array of N numbers, each between O and 1.
I need:

1) the color of nodes i and j has to be the same if array[i] == array[j]
2) the color of edge ij has to be given according to this criterion:
if( array[i] <= array[j] ):
color_of_edge_ij = color_of_node_j
else:
color_of_egde_ij = color of node_j

About the first question I was suggested here (https://lists.nongnu.org/archive/html/igraph-help/2011-04/msg00043.html)
to assign manually the color to each node:

g.vs[0]["color"] = "red"
g.vs[1]["color"] = "blue"
.
.
.
g.vs[N]["color"] = "black"

then I can do

for i in (0,N):
for j in (i+1,N):
if (array[i] == array[j]):
g.vs[i]["color"] = g.vs[j]["color"]

This works but if N is a big number is not practicable to assign manually a color to each node.