Ask Your Question
2

Graph theory: Make vertex labels in plots bigger

asked 2012-12-12 16:51:15 +0100

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
3

answered 2012-12-13 07:01:41 +0100

updated 2012-12-15 10:48:12 +0100

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

Comments

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 14:04:03 +0100 )edit
2

answered 2012-12-12 21:18:39 +0100

ppurka gravatar image

I have opened #13827 for this.

edit flag offensive delete link more
1

answered 2014-03-31 09:29:48 +0100

alejandroerickson gravatar image

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

P = graphs.PetersenGraph()
P.show(figsize=[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

Stats

Asked: 2012-12-12 16:51:15 +0100

Seen: 2,005 times

Last updated: Mar 31 '14