ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 21 Dec 2015 14:21:58 +0100Tree layout of a graphhttps://ask.sagemath.org/question/31513/tree-layout-of-a-graph/ Consider the graph of this tree:
T = Graph()
E = [(0, 1), (1, 2), (2, 3), (2, 4)]
T.add_edges(E);
T.show(layout='tree',tree_root=0,tree_orientation='down')
![image description](/upfiles/14499200675194864.png)
I would like to see the edges displayed in the order as given in the list E from left to right.
In other words, I would like to have node(4) exchange its position with node(3).
How can I achieve this?
*Edit:* To clarify: Changing the order of the edge-list is no option
(besides not working either). The order of the edges must be adhered
to the order given.Sat, 12 Dec 2015 12:42:23 +0100https://ask.sagemath.org/question/31513/tree-layout-of-a-graph/Answer by ndomes for <p>Consider the graph of this tree:</p>
<pre><code>T = Graph()
E = [(0, 1), (1, 2), (2, 3), (2, 4)]
T.add_edges(E);
T.show(layout='tree',tree_root=0,tree_orientation='down')
</code></pre>
<p><img alt="image description" src="/upfiles/14499200675194864.png"/></p>
<p>I would like to see the edges displayed in the order as given in the list E from left to right.
In other words, I would like to have node(4) exchange its position with node(3).</p>
<p>How can I achieve this?</p>
<p><em>Edit:</em> To clarify: Changing the order of the edge-list is no option
(besides not working either). The order of the edges must be adhered
to the order given.</p>
https://ask.sagemath.org/question/31513/tree-layout-of-a-graph/?answer=31529#post-id-31529 I tried with success changing the order of edges in E **and** converting to strings.
T = Graph()
E = [(0, 1), (1, 2), (2, 4), (2, 3)]
E = [map(str,e) for e in E]
T.add_edges(E);
T.show(layout='tree',tree_root='0',tree_orientation='down')
Sat, 12 Dec 2015 21:18:11 +0100https://ask.sagemath.org/question/31513/tree-layout-of-a-graph/?answer=31529#post-id-31529Comment by Peter Luschny for <p>I tried with success changing the order of edges in E <strong>and</strong> converting to strings.</p>
<pre><code>T = Graph()
E = [(0, 1), (1, 2), (2, 4), (2, 3)]
E = [map(str,e) for e in E]
T.add_edges(E);
T.show(layout='tree',tree_root='0',tree_orientation='down')
</code></pre>
https://ask.sagemath.org/question/31513/tree-layout-of-a-graph/?comment=31533#post-id-31533I do not want to change the order of the edges. This is a minimal example; in reality the edges are a large and complicated sequence computed by a program. I want to persuade Sage to respect the order of the edges as given.Sat, 12 Dec 2015 22:40:18 +0100https://ask.sagemath.org/question/31513/tree-layout-of-a-graph/?comment=31533#post-id-31533Answer by FrédéricC for <p>Consider the graph of this tree:</p>
<pre><code>T = Graph()
E = [(0, 1), (1, 2), (2, 3), (2, 4)]
T.add_edges(E);
T.show(layout='tree',tree_root=0,tree_orientation='down')
</code></pre>
<p><img alt="image description" src="/upfiles/14499200675194864.png"/></p>
<p>I would like to see the edges displayed in the order as given in the list E from left to right.
In other words, I would like to have node(4) exchange its position with node(3).</p>
<p>How can I achieve this?</p>
<p><em>Edit:</em> To clarify: Changing the order of the edge-list is no option
(besides not working either). The order of the edges must be adhered
to the order given.</p>
https://ask.sagemath.org/question/31513/tree-layout-of-a-graph/?answer=31563#post-id-31563You can use instead planar graphs by setting the embedding:
sage: T = Graph()
sage: E = [(0, 1), (1, 2), (2, 3), (2, 4)]
sage: T.add_edges(E)
sage: T.set_embedding({0:[1],1:[0,2],2:[1,3,4],3:[2],4:[2]})
sage: T.show()
Mon, 14 Dec 2015 20:15:45 +0100https://ask.sagemath.org/question/31513/tree-layout-of-a-graph/?answer=31563#post-id-31563Comment by Peter Luschny for <p>You can use instead planar graphs by setting the embedding:</p>
<pre><code>sage: T = Graph()
sage: E = [(0, 1), (1, 2), (2, 3), (2, 4)]
sage: T.add_edges(E)
sage: T.set_embedding({0:[1],1:[0,2],2:[1,3,4],3:[2],4:[2]})
sage: T.show()
</code></pre>
https://ask.sagemath.org/question/31513/tree-layout-of-a-graph/?comment=31737#post-id-31737This might work; however the 'set_embedding' requires additional work with the edges and is not satisfying as it is completely unnecessary since the requested embedding is already there: implicitly in the list of the edges. All I want is that Sage respects the given order instead of messing it up. Thus my question seems to amount to a quite natural feature request.Mon, 21 Dec 2015 14:21:58 +0100https://ask.sagemath.org/question/31513/tree-layout-of-a-graph/?comment=31737#post-id-31737