First time here? Check out the FAQ!

Ask Your Question
0

Graph: colored edge labels

asked 10 years ago

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?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 10 years ago

tmonteil gravatar image

updated 10 years ago

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'})
Preview: (hide)
link

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 ( 10 years ago )

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: 10 years ago

Seen: 1,745 times

Last updated: Jan 06 '15