graph plot: size of arrow heads

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 close merge delete

( 2023-07-07 16:03:17 +0200 )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://'

( 2023-08-31 16:39:25 +0200 )edit

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

( 2023-08-31 16:53:43 +0200 )edit

Sort by » oldest newest most voted

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 = 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!

more

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

( 2023-09-03 19:05:20 +0200 )edit