Ask Your Question
0

graph vertex labels placement or alignment

asked 2014-03-31 09:40:01 +0100

alejandroerickson gravatar image

updated 2015-01-13 21:55:15 +0100

FrédéricC gravatar image

I made a sage Graph() for visualizing a bibliography and found that there was no good way to align or change the placement of the vertex labels.

I wanted some labels to align left and others to align right, but they were all centred on their vertex. I ended up doubling the length of the label string with spaces and adding a period with some code like the following

    lDict = {}
for v in G.vertices():
    if <test for the type of vertex>:
        lDict[v] = v + len(v)*' ' + '.'
    else:
        lDict[v] = ''.join(['.',len(v)*' ',v])
G.relabel(lDict)

I managed to get this (click for full sized image):

Graph

Is there a way to manipulate the placement of the labels?

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2014-03-31 10:24:44 +0100

Nathann gravatar image

No way that I know. But Sage is an open-source project, so if you have a good idea for that, you are welcome to contribute !

Nathann

edit flag offensive delete link more
1

answered 2014-03-31 12:03:34 +0100

kcrisman gravatar image

I believe you'll want to use the optional tikz interface, lovely described (complete with vertex label positioning) at this location.

edit flag offensive delete link more

Comments

1

The example is pretty. I think I might use the tikz graphs every time!

alejandroerickson gravatar imagealejandroerickson ( 2014-03-31 12:34:51 +0100 )edit

Great! I have to admit tikz is pretty awesome - the learning curve is worth it. If this solved your problem, please accept the answer so other people searching this question will see it was solved.

kcrisman gravatar imagekcrisman ( 2014-04-01 10:23:37 +0100 )edit

As of now it doesn't work on my installation, but I'll select it when it works for me. Thanks!

alejandroerickson gravatar imagealejandroerickson ( 2014-04-01 11:18:32 +0100 )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

1 follower

Stats

Asked: 2014-03-31 09:40:01 +0100

Seen: 871 times

Last updated: Mar 31 '14