Ask Your Question
1

Line graph of a given graph

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

anonymous user

Anonymous

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

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.

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()
edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
2

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

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).

sage: h.show(method='js',link_distance=100)
edit flag offensive delete link more
0

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

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

Comments

Can you give us a link to the exact place? While http://doc.sagemath.org/html/en/refer... has references to vertex_size, the line_graphdoc (http://doc.sagemath.org/html/en/refer...) 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 +0100 )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

Stats

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

Seen: 465 times

Last updated: Sep 15 '17