Ask Your Question

mesri's profile - activity

2017-03-03 13:27:22 +0200 received badge  Famous Question (source)
2015-12-04 17:55:48 +0200 received badge  Notable Question (source)
2014-12-10 15:55:48 +0200 received badge  Popular Question (source)
2012-09-30 22:04:47 +0200 commented answer Coloring edges by their labels

Thanks! That does it. So what is the relationship between the parameters edge_color, color_by_label, edge_colors, and this function graph._color_by_label ?

2012-09-30 21:57:40 +0200 received badge  Scholar (source)
2012-09-30 21:57:40 +0200 marked best answer Coloring edges by their labels

It seems that the color_by_label option from the plot function just uses as many colors as labels from the sage.plot.colors.rainbow function. That is, the color is not taken from the labels themselves but from the rainbow function.

Maybe the following example can help you obtain the plot settings you want.

g=graphs.IcosahedralGraph()
for e in g.edges():
    g.set_edge_label(e[0],e[1],1 if e[0]%2 or e[1]%2 else 2)
d={1: "blue", 2: "green"} # _color_by_label will use this to map labels to colors
g.plot(edge_colors=g._color_by_label(d))

This produced the following output. image description

2012-09-30 21:57:25 +0200 received badge  Supporter (source)
2012-09-28 17:50:02 +0200 received badge  Autobiographer
2012-09-28 17:39:41 +0200 asked a question Coloring edges by their labels

I'm trying to understand how to use the color_by_label parameter of the Graph.plot() function to set edge colors depending on various conditions. I cannot seem to get any colors to display other than cyan and red, no matter what I put in the edge labels, and, as in the linked image, I cannot seem to reliably get the colors to go with the labels.

In my example, I was trying to set edge color to blue if either of the vertices of an edge is odd, red otherwise.

(Sorry for the external link -- I apparently need to acquire some karma before I can post it here)

Screen Shot of sage notebook session and graphics output

version. Sage 5.0.1 on Mac OS X 10.8.1, notebook running in Chrome