Ask Your Question

Graph theory: Make vertex labels in plots bigger

asked 2012-12-12 09:51:15 -0500

G-Sage gravatar image

Is it possible to make the labels for the vertices of graphs bigger? I can make the vertices themselves bigger but that doesn't seem to change the size of the labels.

Thank you.

edit retag flag offensive close merge delete

3 answers

Sort by » oldest newest most voted

answered 2012-12-13 00:01:41 -0500

updated 2012-12-15 03:48:12 -0500

Imho it's easier to write a few lines of code to plot graphs using plotting primitives, something like code below. S denotes my graph (a simple dictionary, for each key u, S[u] is the list of neighbours), xy is a dictionary which indicates positions of vertices, defined elsewhere as are ms (vertex size) and fs (font size).

    G = Graphics()
    p = [xy[u] for u in S]
    c = [my_color(u) for u in S]
    G += scatter_plot (p, markersize = ms, facecolor = c, **kwds)
    for u in S:
        for v in S[u]:
            G += line ([xy[u], xy[v]])
    G += sum (text (my_str(u), xy[u], fontsize = fs, zorder = 10) for u in S)

It's that simple, and anything (position, size, color of vertices, font size, text to display for each vertex) is under control.

edit flag offensive delete link more


It may be easier if you know how to do it. :) I could learn a thing or two from studying your code. For me, it's easier for ppurka to make a tracticket and create a new feature :) The problem is it'll take 1 month before it's on our Sage server, but I don't need it that badly. All kidding aside, though this is more of an advanced technique for someone like me, this is a very good thing to know. So, thanks for your answer.

G-Sage gravatar imageG-Sage ( 2012-12-13 07:04:03 -0500 )edit

answered 2012-12-12 14:18:39 -0500

ppurka gravatar image

I have opened #13827 for this.

edit flag offensive delete link more

answered 2014-03-31 02:29:48 -0500

alejandroerickson gravatar image

One way is to use figsize to indirectly change the relative size of the labels.

P = graphs.PetersenGraph()[1,1],vertex_size=0,layout='spring')

The output of this is:

Mangled Petersen graph with large labels.

edit flag offensive delete link more

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: 2012-12-12 09:51:15 -0500

Seen: 730 times

Last updated: Mar 31 '14