Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

graph vertex labels placement or alignment

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?

click to hide/show revision 2
retagged

graph vertex labels placement or alignment

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?