Ask Your Question

Line graph of a given graph

asked 2017-09-14 12:38:12 +0200

anonymous user


updated 2017-09-14 15:24:27 +0200

kcrisman gravatar image

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.



h = G.line_graph()
edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2017-09-15 07:46:19 +0200

The 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, or use the Javascript plotting (it's better to increase the link distance).

edit flag offensive delete link more

answered 2017-09-14 13:47:08 +0200

FrédéricC gravatar image

You could try to read the documentation.

sage: h.relabel(lambda u:u[:2])
sage: h.plot(figsize=12,vertex_size=1200)
edit flag offensive delete link more


Can you give us a link to the exact place? While has references to vertex_size, the line_graphdoc ( doesn't mention it. And your relabeling is pretty hermetic if the user doesn't know much Python yet.

kcrisman gravatar imagekcrisman ( 2017-09-14 15:28:59 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2017-09-14 12:38:12 +0200

Seen: 406 times

Last updated: Sep 15 '17