Ask Your Question

Font size for edge label

asked 2011-07-17 02:44:41 -0500

Eugene gravatar image

Simple example:

d = DiGraph()
d.add_edge(1, 2, '$a_0$')

gives me extremely small edge label 'a0', is it possible to increase font size for all edge labels?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2011-07-25 00:27:48 -0500

parzan gravatar image

This one took me some time. It can be achieved by opening YOUR_SAGE_DIR/local/lib/python2.6/site-packages/sage/graphs/ and changing the line

self._plot_components['edge_labels'].append(text(str(edges_to_draw[(a,b)][0][0]),[(self._pos[a][0]+self._pos[b][0])/2., (self._pos[a][1]+self._pos[b][1])/2.]))


self._plot_components['edge_labels'].append(text(str(edges_to_draw[(a,b)][0][0]),[(self._pos[a][0]+self._pos[b][0])/2., (self._pos[a][1]+self._pos[b][1])/2.],fontsize=20))

There is no need to compile anything, just save the file and then run sage.

Remark: in the mentioned file there are 5 lines starting with


so to be on the safe side you can change all of them (adding fontsize=20 as a last parameter to the text function). I suspect they handle different situations (directed/undirected graphs, etc.). You can put DEFAULT_FONTSIZE = 20 at the beginning of the file and then add fontsize=DEFAULT_FONTSIZE to the text functions - this will allow you to change the size easily later.

edit flag offensive delete link more


Nice work -- this bug should be reported and fixed :) Can you add label_font_size to the rest of the options for graphs?

niles gravatar imageniles ( 2011-07-25 02:36:22 -0500 )edit

I don't think this is a bug, just something no one implemented yet, so it is more of a "feature request". Does sage has a place for such requests?

parzan gravatar imageparzan ( 2011-07-29 05:01:30 -0500 )edit

yep -- the trac server ( lets you select whether the issue you're reporting is a bug or an enhancement.

niles gravatar imageniles ( 2011-07-29 05:17:13 -0500 )edit

I concur that you should file a ticket to make this customizable.

kcrisman gravatar imagekcrisman ( 2011-07-29 08:40:09 -0500 )edit

Also, it's better to change the YOUR_SAGE_DIR/devel/sage/sage/graphs/ file and then build, because Sage will automatically keep track of the changes you have made and make it easier to see what you have and haven't changed.

kcrisman gravatar imagekcrisman ( 2011-07-29 08:40:56 -0500 )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


Asked: 2011-07-17 02:44:41 -0500

Seen: 475 times

Last updated: Jul 25 '11