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.Tue, 16 Jan 2018 21:21:29 +0100Drawing a planar multigraph with loopshttps://ask.sagemath.org/question/40548/drawing-a-planar-multigraph-with-loops/ I would like to draw a planar graph with multiple edges and loops in Sage. Unfortunately, the default algorithm draws may intersecting edges and Sage is unable to compute an embedding for graphs with loops multiple edges.
Fortunately I know a planar embedding of this graph, so I tried using the `set_embedding` method, but it doesn't seem to work, either. If I only list a vertice's the neighbours, omitting their multiplicities, Sage complains that the list is shorter than the vertice's degree, while if I include multiple copies of each neighbour according to multiplicity, then Sage complains that elements of the list aren't unique.
Is there a way to achieve what I need?Wed, 10 Jan 2018 14:00:59 +0100https://ask.sagemath.org/question/40548/drawing-a-planar-multigraph-with-loops/Comment by slelievre for <p>I would like to draw a planar graph with multiple edges and loops in Sage. Unfortunately, the default algorithm draws may intersecting edges and Sage is unable to compute an embedding for graphs with loops multiple edges.</p>
<p>Fortunately I know a planar embedding of this graph, so I tried using the <code>set_embedding</code> method, but it doesn't seem to work, either. If I only list a vertice's the neighbours, omitting their multiplicities, Sage complains that the list is shorter than the vertice's degree, while if I include multiple copies of each neighbour according to multiplicity, then Sage complains that elements of the list aren't unique.</p>
<p>Is there a way to achieve what I need?</p>
https://ask.sagemath.org/question/40548/drawing-a-planar-multigraph-with-loops/?comment=40557#post-id-40557Please provide code to generate the graph you are interested in.
This will make it a lot easier for other users to try to answer your question.
You can also say what you have tried and show how it fails and say what you would expect instead.Thu, 11 Jan 2018 07:58:28 +0100https://ask.sagemath.org/question/40548/drawing-a-planar-multigraph-with-loops/?comment=40557#post-id-40557Answer by Sébastien for <p>I would like to draw a planar graph with multiple edges and loops in Sage. Unfortunately, the default algorithm draws may intersecting edges and Sage is unable to compute an embedding for graphs with loops multiple edges.</p>
<p>Fortunately I know a planar embedding of this graph, so I tried using the <code>set_embedding</code> method, but it doesn't seem to work, either. If I only list a vertice's the neighbours, omitting their multiplicities, Sage complains that the list is shorter than the vertice's degree, while if I include multiple copies of each neighbour according to multiplicity, then Sage complains that elements of the list aren't unique.</p>
<p>Is there a way to achieve what I need?</p>
https://ask.sagemath.org/question/40548/drawing-a-planar-multigraph-with-loops/?answer=40644#post-id-40644Install graphviz on your system and install dot2tex:
sage -i dot2tex
Use it to generate tikz code:
sage: G = ... your graph ....
sage: kwds = dict(format='dot2tex', edge_labels=True, color_by_label=False, prog='dot')
sage: G.latex_options().set_options(**kwds)
sage: tikz = graph._latex_()
View it:
sage: view(G)
You may test `prog='neato'` for another type of node placement.Tue, 16 Jan 2018 21:21:29 +0100https://ask.sagemath.org/question/40548/drawing-a-planar-multigraph-with-loops/?answer=40644#post-id-40644