ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 01 Apr 2014 04:18:32 -0500graph vertex labels placement or alignmenthttp://ask.sagemath.org/question/11349/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](http://alejandroerickson.com/home/blog/im/small_bibgraph.jpg)](http://alejandroerickson.com/home/blog/im/full_sized_bibgraph.png)
Is there a way to manipulate the placement of the labels?Mon, 31 Mar 2014 02:40:01 -0500http://ask.sagemath.org/question/11349/graph-vertex-labels-placement-or-alignment/Answer by kcrisman for <p>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.</p>
<p>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</p>
<pre><code> 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)
</code></pre>
<p>I managed to get this (click for full sized image):</p>
<p><a href="http://alejandroerickson.com/home/blog/im/full_sized_bibgraph.png"><img alt="Graph" src="http://alejandroerickson.com/home/blog/im/small_bibgraph.jpg"/></a></p>
<p>Is there a way to manipulate the placement of the labels?</p>
http://ask.sagemath.org/question/11349/graph-vertex-labels-placement-or-alignment/?answer=16109#post-id-16109I believe you'll want to use the optional tikz interface, lovely described (complete with vertex label positioning) at [this location](http://www.sagemath.org/doc/reference/graphs/sage/graphs/graph_latex.html#sage.graphs.graph_latex.GraphLatex.set_option).Mon, 31 Mar 2014 05:03:34 -0500http://ask.sagemath.org/question/11349/graph-vertex-labels-placement-or-alignment/?answer=16109#post-id-16109Comment by alejandroerickson for <p>I believe you'll want to use the optional tikz interface, lovely described (complete with vertex label positioning) at <a href="http://www.sagemath.org/doc/reference/graphs/sage/graphs/graph_latex.html#sage.graphs.graph_latex.GraphLatex.set_option">this location</a>.</p>
http://ask.sagemath.org/question/11349/graph-vertex-labels-placement-or-alignment/?comment=16208#post-id-16208As of now it doesn't work on my installation, but I'll select it when it works for me. Thanks!Tue, 01 Apr 2014 04:18:32 -0500http://ask.sagemath.org/question/11349/graph-vertex-labels-placement-or-alignment/?comment=16208#post-id-16208Comment by alejandroerickson for <p>I believe you'll want to use the optional tikz interface, lovely described (complete with vertex label positioning) at <a href="http://www.sagemath.org/doc/reference/graphs/sage/graphs/graph_latex.html#sage.graphs.graph_latex.GraphLatex.set_option">this location</a>.</p>
http://ask.sagemath.org/question/11349/graph-vertex-labels-placement-or-alignment/?comment=16210#post-id-16210The example is pretty. I think I might use the tikz graphs every time!Mon, 31 Mar 2014 05:34:51 -0500http://ask.sagemath.org/question/11349/graph-vertex-labels-placement-or-alignment/?comment=16210#post-id-16210Comment by kcrisman for <p>I believe you'll want to use the optional tikz interface, lovely described (complete with vertex label positioning) at <a href="http://www.sagemath.org/doc/reference/graphs/sage/graphs/graph_latex.html#sage.graphs.graph_latex.GraphLatex.set_option">this location</a>.</p>
http://ask.sagemath.org/question/11349/graph-vertex-labels-placement-or-alignment/?comment=16209#post-id-16209Great! 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.Tue, 01 Apr 2014 03:23:37 -0500http://ask.sagemath.org/question/11349/graph-vertex-labels-placement-or-alignment/?comment=16209#post-id-16209Answer by Nathann for <p>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.</p>
<p>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</p>
<pre><code> 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)
</code></pre>
<p>I managed to get this (click for full sized image):</p>
<p><a href="http://alejandroerickson.com/home/blog/im/full_sized_bibgraph.png"><img alt="Graph" src="http://alejandroerickson.com/home/blog/im/small_bibgraph.jpg"/></a></p>
<p>Is there a way to manipulate the placement of the labels?</p>
http://ask.sagemath.org/question/11349/graph-vertex-labels-placement-or-alignment/?answer=16108#post-id-16108No 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 !
NathannMon, 31 Mar 2014 03:24:44 -0500http://ask.sagemath.org/question/11349/graph-vertex-labels-placement-or-alignment/?answer=16108#post-id-16108