igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[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.

About the second question, I'vs tried to adapt the code in 
https://stackoverflow.com/questions/10067721/can-i-change-the-colour-of-edges-containing-specific-vertices-in-igraph-python
to my case but the best I obtained was two different colors.

In practice, I need a way to have univocal correspondence between numbers in [0,1] and colors. How can I obtain this? (maybe using palette?)

thanks in advance. 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]