Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Position of labels in a graph

I'm creating a labeled graph, but the position of the labels is making them difficult to read. For example:

D = DiGraph(multiedges=True)
D.add_edge(var('Vert1'),var('Vert2'),str("Edge1"))
D.add_edge(var('Vert2'),var('Vert3'),str("Edge2"))
D.add_edge(var('Vert1'),var('Vert3'),str("Edge3"))
D.graphplot(edge_labels=True,layout='circular').show()

creates a nice looking graph, but especially Edge1 is difficult to read. Is there a way to move labels away from the edges?

I know there are posts asking similar questions (insufficient karma to post links), though these suggest changing the rule for label location to be something other than the middle of the two points, and I'd rather not have to use the same rule for all labels, as the changes may be different for different vertices.

EDIT: I have a sort-of solution, which is just to add spaces in the label name or line breaks in the label name, which does achieve the goal, but if someone has a better solution, I would be very happy to hear it. E.g.:

D = DiGraph(multiedges=True)
D.add_edge(var('Vert1'),var('Vert2'),str("""Edge1

"""))
D.add_edge(var('Vert2'),var('Vert3'),str("             Edge2"))
D.add_edge(var('Vert1'),var('Vert3'),str("             Edge3"))
D.graphplot(edge_labels=True,layout='circular').show()