Ask Your Question
0

Graph: colored edge labels

asked 2015-01-06 20:10:47 +0200

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 22:07:39 +0200

tmonteil gravatar image

updated 2015-01-06 22:10:10 +0200

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 11:24:10 +0200 )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 20:10:47 +0200

Seen: 1,535 times

Last updated: Jan 06 '15