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.Fri, 15 Sep 2017 00:46:19 -0500Line graph of a given graphhttp://ask.sagemath.org/question/38814/line-graph-of-a-given-graph/I tried this code in sage. But in the output the vertex labelling of the desired line graph gets overlapped and hece the graph is not clearly visible. Can I improve the code so that the line graph is clearly visible without overlapping.
G=graphs.EmptyGraph()
G.add_edges([(2,3),(2,4),(2,1),(1,5),(5,6),(1,0),(0,12),(0,13),(14,0),(15,0),(7,0),(7,10),(11,7),(7,9),(7,8)])
G.show()
h = G.line_graph()
h.show()Thu, 14 Sep 2017 05:38:12 -0500http://ask.sagemath.org/question/38814/line-graph-of-a-given-graph/Answer by David Coudert for <p>I tried this code in sage. But in the output the vertex labelling of the desired line graph gets overlapped and hece the graph is not clearly visible. Can I improve the code so that the line graph is clearly visible without overlapping.</p>
<pre><code>G=graphs.EmptyGraph()
G.add_edges([(2,3),(2,4),(2,1),(1,5),(5,6),(1,0),(0,12),(0,13),(14,0),(15,0),(7,0),(7,10),(11,7),(7,9),(7,8)])
G.show()
h = G.line_graph()
h.show()
</code></pre>
http://ask.sagemath.org/question/38814/line-graph-of-a-given-graph/?answer=38819#post-id-38819The vertices of the `line_graph` are the edges of the graph, including edge labels by default. If you don't want the labels, you can do:
sage: G = Graph([(2,3),(2,4),(2,1),(1,5),(5,6),(1,0),(0,12),(0,13),(14,0),(15,0),(7,0),(7,10),(11,7),(7,9),(7,8)])
sage: h = G.line_graph(labels=False)
Then you can either use the method that has already been proposed [here](https://ask.sagemath.org/question/38814/line-graph-of-a-given-graph/?answer=38815#post-id-38815), or use the [Javascript plotting](http://doc.sagemath.org/html/en/reference/graphs/sage/graphs/graph_plot_js.html) (it's better to increase the link distance).
sage: h.show(method='js',link_distance=100)Fri, 15 Sep 2017 00:46:19 -0500http://ask.sagemath.org/question/38814/line-graph-of-a-given-graph/?answer=38819#post-id-38819Answer by FrédéricC for <p>I tried this code in sage. But in the output the vertex labelling of the desired line graph gets overlapped and hece the graph is not clearly visible. Can I improve the code so that the line graph is clearly visible without overlapping.</p>
<pre><code>G=graphs.EmptyGraph()
G.add_edges([(2,3),(2,4),(2,1),(1,5),(5,6),(1,0),(0,12),(0,13),(14,0),(15,0),(7,0),(7,10),(11,7),(7,9),(7,8)])
G.show()
h = G.line_graph()
h.show()
</code></pre>
http://ask.sagemath.org/question/38814/line-graph-of-a-given-graph/?answer=38815#post-id-38815You could try to read the documentation.
sage: h.relabel(lambda u:u[:2])
sage: h.plot(figsize=12,vertex_size=1200)
Thu, 14 Sep 2017 06:47:08 -0500http://ask.sagemath.org/question/38814/line-graph-of-a-given-graph/?answer=38815#post-id-38815Comment by kcrisman for <p>You could try to read the documentation.</p>
<pre><code>sage: h.relabel(lambda u:u[:2])
sage: h.plot(figsize=12,vertex_size=1200)
</code></pre>
http://ask.sagemath.org/question/38814/line-graph-of-a-given-graph/?comment=38817#post-id-38817Can you give us a link to the exact place? While http://doc.sagemath.org/html/en/reference/plotting/sage/graphs/graph_plot.html has references to `vertex_size`, the `line_graph` doc (http://doc.sagemath.org/html/en/reference/graphs/sage/graphs/generic_graph.html#sage.graphs.generic_graph.GenericGraph.line_graph) doesn't mention it. And your relabeling is pretty hermetic if the user doesn't know much Python yet.Thu, 14 Sep 2017 08:28:59 -0500http://ask.sagemath.org/question/38814/line-graph-of-a-given-graph/?comment=38817#post-id-38817