Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

edge_style for different edges in a multigraph

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!