Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Hello, @pg261! This is not very elegant solution, but I couldn't find any alternative at the moment. However, I believe this should solve your problem.

The following function updates the plotting options for the edges of a graph:

def update_edge_draw_options(g, options):
    G = g.graphplot()  # convert into a GraphPlot object
    # Loop through all the graph's edges:
    for edge in G._plot_components['edges']:
        opts = edge[0].options()  # extract current options for edge
        opts.update(options)  # update with our custom options
        edge[0].set_options(opts)  # set the updated options
    return G

This function is capable of modifying any drawing option for the edges, including arrowsize that determines the head size of the edge. So you could do something like this:

g = Graph()
g.add_vertices([1, 2, 5, 9])
g.add_edges([(1,5), (9,2), (2,5), (1,9)])
g = g.to_directed()

G = update_edge_draw_options(g, {'arrowsize':20})  # set the arrow head size to 20 (very large)
G.plot()

In theory, you could also write a similar function that deals with vertices, but this is out of the scope of this answer.

I imagine there must be a better/simpler way of doing this, but I don't have much experience with Sage's graph capabilities, and unfortunately I didn't have the time to read all the pieces of code that take care of the drawing layout for a graph. Hopefully, someone can come up with a better/simpler/more elegant solution.

I hope this helps!