Ask Your Question
4

graph plot: size of arrow heads

asked 2023-07-06 16:24:05 +0100

pg261 gravatar image

updated 2023-08-31 14:11:48 +0100

FrédéricC gravatar image

Hi !

I was wondering how I could reduce the size of arrow heads while plotting a directed graph. I haven't got enough "points" to upload a picture, but you can easily understand what happens : I have a directed graph with many vertices, I use vertex_size= something small, but the arrow heads are very very large and the whole thing looks weird.

any idea?

thanks!

edit retag flag offensive close merge delete

Comments

Welcome to Ask Sage! Thank you for your question.

slelievre gravatar imageslelievre ( 2023-07-07 16:03:17 +0100 )edit

maybe look at this graph below and try to change width and radius, tell us if it is what you want or not:

graph with arrows

maybe you can put your code in sagecell.sagemath.org/ and put the link you will get with clicking the share button short temp lnk, then put the link in your message without the 'https://'

ortollj gravatar imageortollj ( 2023-08-31 16:39:25 +0100 )edit

oops maybe I'm off topic, and these arrows are integrated into a special graph, sorry if that's the case.;-(

ortollj gravatar imageortollj ( 2023-08-31 16:53:43 +0100 )edit

1 Answer

Sort by » oldest newest most voted
2

answered 2023-09-02 08:55:10 +0100

dsejas gravatar image

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!

edit flag offensive delete link more

Comments

yes indeed @dsejas, it works very well to adjust the sizes of the arrows for the graphs.

ortollj gravatar imageortollj ( 2023-09-03 19:05:20 +0100 )edit

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: 2023-07-06 16:24:05 +0100

Seen: 378 times

Last updated: Sep 02 '23