Ask Your Question
1

edge_style for different edges in a multigraph

asked 2016-04-26 02:17:33 +0200

mthomas gravatar image

I'm trying to make a directed multigraph in which different edges have colors/edge styles so that they can be easy read either in color or in black and white.

I can make a graph with different colors:

D = DiGraph(multiedges=True)
var('A,B')
D.add_edge(A,B,'edge1')
D.add_edge(A,B,'edge2')
D.graphplot(color_by_label={'edge1':'green','edge2':'blue'}).show()

I can also make a graph with different styles, but overlayed:

G1 = DiGraph(multiedges=True)
G2 = DiGraph(multiedges=True)
var('A,B')
G1.add_edge(A,B,'edge1')
G2.add_edge(A,B,'edge2')
G1.set_pos({A:[0,0],B:[1,0]})
G2.set_pos({A:[0,0],B:[1,0]})
G = G1.graphplot(color_by_label={'edge1':'green'}, edge_style='--').plot() + G2.graphplot(color_by_label={'edge2':'blue'}, edge_style=':').plot()
G.show(axes=False)

and a very hack-y solution which looks nicer, but still bad:

G1 = DiGraph(multiedges=True)
G2 = DiGraph(multiedges=True)
var('A,B')
G1.add_edge(A,B,'edge1')
G2.add_edge(A,B,'edge2')
G1.add_edge(A,B,'edge2')
G2.add_edge(A,B,'edge1')
G1.set_pos({A:[0,0],B:[1,0]})
G2.set_pos({A:[0,0],B:[1,0]})
G = G1.graphplot(color_by_label={'edge1':'green','edge2':'white'}, edge_style='--').plot() + G2.graphplot(color_by_label={'edge2':'blue','edge1':'white'}, edge_style=':').plot()
G.show(axes=False)

I'd love to be able to have a multigraph where the edges are both different colors and different styles and don't completely overlap, but I'm not seeing a way to do this. Any help is appreciated!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-04-26 13:22:44 +0200

mthomas gravatar image

I'm going to self-post a reasonable solution, in hopes that someone comes up with a better one, which is to use the dist argument in the graph so the edges aren't on top of each other:

G1 = DiGraph(multiedges=True)
G2 = DiGraph(multiedges=True)
var('A,B')
G1.add_edge(A,B,'edge1')
G2.add_edge(A,B,'edge2')
G1.add_edge(A,B,'edge2')
G2.add_edge(A,B,'edge1')
G1.set_pos({A:[0,0],B:[1,0]})
G2.set_pos({A:[0,0],B:[1,0]})
G = G1.graphplot(color_by_label={'edge1':'green','edge2':'white'}, edge_style='--', dist=0.75).plot() + G2.graphplot(color_by_label={'edge2':'blue','edge1':'white'}, edge_style=':').plot()
G.show(axes=False)
edit flag offensive delete link more

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: 2016-04-26 02:17:33 +0200

Seen: 534 times

Last updated: Apr 26 '16