First time here? Check out the FAQ!

Ask Your Question
4

graph plot: size of arrow heads

asked 1 year ago

pg261 gravatar image

updated 1 year ago

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!

Preview: (hide)

Comments

Welcome to Ask Sage! Thank you for your question.

slelievre gravatar imageslelievre ( 1 year ago )

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 ( 1 year ago )

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

ortollj gravatar imageortollj ( 1 year ago )

1 Answer

Sort by » oldest newest most voted
2

answered 1 year ago

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!

Preview: (hide)
link

Comments

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

ortollj gravatar imageortollj ( 1 year ago )

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: 1 year ago

Seen: 447 times

Last updated: Sep 02 '23