Ask Your Question
0

Graph: colored edge labels

asked 2015-01-06 13:10:47 -0500

anonymous user

Anonymous

I'm trying to plot a graph with labels on the edges as follows:

G = Graph(multiedges=True)
G.add_edges( [(0,1,'a'),(1,2,'b'),(2,3,'c'),(3,4,'b'),(4,0,'a')] )
H = G.plot(edge_labels=True, graph_border=True)
H.show()

Is it possible to color the edge labels, e.g. making the "a" red, "b" blue etc?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2015-01-06 15:07:39 -0500

tmonteil gravatar image

updated 2015-01-06 15:10:10 -0500

It is doable as follows:

sage: G.plot(color_by_label={'a':'red', 'b':'blue', 'c':'green'})

If you are lazy, you can let Sage decide the colors for you:

sage: G.plot(color_by_label=True)

Of course you can use the other options if needed:

sage: G.plot(edge_labels=True, graph_border=True, color_by_label={'a':'red', 'b':'blue', 'c':'green'})
edit flag offensive delete link more

Comments

Is it also possible to color parts of the label differently, e.g. instead of making "label a" completely red, would it be possible to make the substring 'label' red and 'a' green? Or is it possible to use LATEX /HTML code for this string formatting?

herb gravatar imageherb ( 2015-01-08 04:24:10 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-01-06 13:10:47 -0500

Seen: 471 times

Last updated: Jan 06 '15