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.Mon, 14 Nov 2016 15:40:05 -0600Is there a way to draw a graph using a specific embedding?http://ask.sagemath.org/question/35533/is-there-a-way-to-draw-a-graph-using-a-specific-embedding/ It is possible to set the embedding of a graph ([set_embedding](http://doc.sagemath.org/html/en/reference/graphs/sage/graphs/generic_graph.html#sage.graphs.generic_graph.GenericGraph.set_embedding)), but `plot()` doesn't seem to respect it. Is there a way to plot the graph using the specified embedding?
Here is an example showing that `faces()` respects the embedding, although plotting each gives the same output:
sage: G = Graph({0:[1,2,3], 2:[3], 3:[4]})
sage: G.faces()
[[(0, 1), (1, 0), (0, 2), (2, 3), (3, 4), (4, 3), (3, 0)],
[(2, 0), (0, 3), (3, 2)]]
sage: G.set_embedding({0:[2,1,3], 1:[0], 2:[0,3], 3:[0,2,4], 4:[3]})
sage: G.faces()
[[(0, 1), (1, 0), (0, 3), (3, 2), (2, 0)],
[(3, 0), (0, 2), (2, 3), (3, 4), (4, 3)]]Fri, 11 Nov 2016 15:24:18 -0600http://ask.sagemath.org/question/35533/is-there-a-way-to-draw-a-graph-using-a-specific-embedding/Comment by FrédéricC for <p>It is possible to set the embedding of a graph (<a href="http://doc.sagemath.org/html/en/reference/graphs/sage/graphs/generic_graph.html#sage.graphs.generic_graph.GenericGraph.set_embedding">set_embedding</a>), but <code>plot()</code> doesn't seem to respect it. Is there a way to plot the graph using the specified embedding?</p>
<p>Here is an example showing that <code>faces()</code> respects the embedding, although plotting each gives the same output:</p>
<pre><code>sage: G = Graph({0:[1,2,3], 2:[3], 3:[4]})
sage: G.faces()
[[(0, 1), (1, 0), (0, 2), (2, 3), (3, 4), (4, 3), (3, 0)],
[(2, 0), (0, 3), (3, 2)]]
sage: G.set_embedding({0:[2,1,3], 1:[0], 2:[0,3], 3:[0,2,4], 4:[3]})
sage: G.faces()
[[(0, 1), (1, 0), (0, 3), (3, 2), (2, 0)],
[(3, 0), (0, 2), (2, 3), (3, 4), (4, 3)]]
</code></pre>
http://ask.sagemath.org/question/35533/is-there-a-way-to-draw-a-graph-using-a-specific-embedding/?comment=35546#post-id-35546I would say that there is currently no way in sage to achieve that. You need to code that yourself.Sat, 12 Nov 2016 10:43:25 -0600http://ask.sagemath.org/question/35533/is-there-a-way-to-draw-a-graph-using-a-specific-embedding/?comment=35546#post-id-35546Answer by fidbc for <p>It is possible to set the embedding of a graph (<a href="http://doc.sagemath.org/html/en/reference/graphs/sage/graphs/generic_graph.html#sage.graphs.generic_graph.GenericGraph.set_embedding">set_embedding</a>), but <code>plot()</code> doesn't seem to respect it. Is there a way to plot the graph using the specified embedding?</p>
<p>Here is an example showing that <code>faces()</code> respects the embedding, although plotting each gives the same output:</p>
<pre><code>sage: G = Graph({0:[1,2,3], 2:[3], 3:[4]})
sage: G.faces()
[[(0, 1), (1, 0), (0, 2), (2, 3), (3, 4), (4, 3), (3, 0)],
[(2, 0), (0, 3), (3, 2)]]
sage: G.set_embedding({0:[2,1,3], 1:[0], 2:[0,3], 3:[0,2,4], 4:[3]})
sage: G.faces()
[[(0, 1), (1, 0), (0, 3), (3, 2), (2, 0)],
[(3, 0), (0, 2), (2, 3), (3, 4), (4, 3)]]
</code></pre>
http://ask.sagemath.org/question/35533/is-there-a-way-to-draw-a-graph-using-a-specific-embedding/?answer=35554#post-id-35554I think you may be able to use the `layout` flag for plot.
G.plot(layout='planar')
That should respect the embedding you have set. If the embedding is "not planar" an exception is raised.
![planar drawing](/upfiles/1479000186321035.png)
The full list of plotting options should be listed [here](http://doc.sagemath.org/html/en/reference/graphs/sage/graphs/graph_plot.html).Sat, 12 Nov 2016 19:22:11 -0600http://ask.sagemath.org/question/35533/is-there-a-way-to-draw-a-graph-using-a-specific-embedding/?answer=35554#post-id-35554Comment by fidbc for <p>I think you may be able to use the <code>layout</code> flag for plot.</p>
<pre><code>G.plot(layout='planar')
</code></pre>
<p>That should respect the embedding you have set. If the embedding is "not planar" an exception is raised.</p>
<p><img alt="planar drawing" src="/upfiles/1479000186321035.png"></p>
<p>The full list of plotting options should be listed <a href="http://doc.sagemath.org/html/en/reference/graphs/sage/graphs/graph_plot.html">here</a>.</p>
http://ask.sagemath.org/question/35533/is-there-a-way-to-draw-a-graph-using-a-specific-embedding/?comment=35578#post-id-35578There is a reference to the documentation of the `sage.graphs.graph_plot` module in the note, but it is not made explicit that there are some "hidden" features there ;-)Mon, 14 Nov 2016 15:40:05 -0600http://ask.sagemath.org/question/35533/is-there-a-way-to-draw-a-graph-using-a-specific-embedding/?comment=35578#post-id-35578Comment by tmonteil for <p>I think you may be able to use the <code>layout</code> flag for plot.</p>
<pre><code>G.plot(layout='planar')
</code></pre>
<p>That should respect the embedding you have set. If the embedding is "not planar" an exception is raised.</p>
<p><img alt="planar drawing" src="/upfiles/1479000186321035.png"></p>
<p>The full list of plotting options should be listed <a href="http://doc.sagemath.org/html/en/reference/graphs/sage/graphs/graph_plot.html">here</a>.</p>
http://ask.sagemath.org/question/35533/is-there-a-way-to-draw-a-graph-using-a-specific-embedding/?comment=35557#post-id-35557I wonder why this does not appear in the doc of `G.plot?`Sun, 13 Nov 2016 02:51:54 -0600http://ask.sagemath.org/question/35533/is-there-a-way-to-draw-a-graph-using-a-specific-embedding/?comment=35557#post-id-35557