Ask Your Question
2

Graph theory: Make vertex labels in plots bigger

asked 12 years ago

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.

Preview: (hide)

3 Answers

Sort by » oldest newest most voted
3

answered 12 years ago

updated 12 years ago

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.

Preview: (hide)
link

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 ( 12 years ago )
2

answered 12 years ago

ppurka gravatar image

I have opened #13827 for this.

Preview: (hide)
link
1

answered 11 years ago

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.

Preview: (hide)
link

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: 12 years ago

Seen: 2,093 times

Last updated: Mar 31 '14