[Top][All Lists]

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

Re: [igraph] dot files coloring

From: Tamas Nepusz
Subject: Re: [igraph] dot files coloring
Date: Wed, 30 Jul 2008 22:12:45 +0200


If i want to plot, inside igraph or neato in the shell, the graph, and
i want to promote my 'state' attribute to the color of the node (i am
doing some work on graph coloring), how can i do?
Assign values to the "color" attribute of the vertices, e.g.:

g.vs[0]["color"] = "red"

sets the color of vertex 0 to red.

let's suppose i have 3 states, [0,1,2], and i want to map 0->green,
1->red, 2->blue and the plot the resulting graph with those colors,
what should i do?
Try this:

color_mapping = { 0: "green", 1: "red", 2: "blue" }
g.vs["color"] = [color_mapping[state] for state in g.vs["state"]]

The Python interface understands most English color names and RGB color specifications in the format of "#rrggbb" (like in HTML).

An alternative is to specify vertex colors as a keyword argument to the plotting function:

plot(g, [...other keyword arguments...], \
   vertex_color = [color_mapping[state] for state in g.vs["state"]])


reply via email to

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