Ask Your Question
0

How to draw CubeGraph(5) better?

asked 2023-02-17 13:28:17 +0100

licheng gravatar image

updated 2023-02-21 03:00:43 +0100

I want to find a minimum dominating set of CubeGraph(5) and display it. However, I found that the drawing of CubeGraph(5) is very poor, with overlapping vertices and intersections between vertices and edges. How can I make Sage provide a slightly better drawing?

g1 = graphs.CubeGraph(5)
g1.relabel()
m=g1.dominating_set()
g1.plot(vertex_colors={"red": m})

image description

g2.to_dictionary()

{0: [1, 17, 19, 22, 7], 1: [0, 2, 6, 23, 25], 2: [1, 21, 22, 26, 29], 3: [18, 19, 7, 11, 27], 4: [16, 17, 22, 29, 31], 5: [17, 19, 11, 13, 31], 6: [1, 7, 10, 26, 27], 7: [0, 3, 6, 8, 15], 8: [16, 18, 22, 7, 26], 9: [16, 18, 11, 12, 31], 10: [6, 25, 30, 14, 15], 11: [3, 5, 9, 14, 15], 12: [20, 9, 28, 30, 14], 13: [5, 23, 25, 28, 14], 14: [10, 11, 27, 12, 13], 15: [16, 17, 7, 10, 11], 16: [4, 8, 9, 30, 15], 17: [0, 4, 5, 25, 15], 18: [3, 20, 8, 24, 9], 19: [0, 3, 5, 23, 24], 20: [18, 21, 26, 27, 12], 21: [2, 20, 23, 24, 28], 22: [0, 2, 4, 8, 24], 23: [1, 19, 21, 27, 13], 24: [18, 19, 21, 22, 31], 25: [1, 17, 10, 13, 29], 26: [2, 20, 6, 8, 30], 27: [3, 20, 6, 23, 14], 28: [21, 12, 13, 29, 31], 29: [2, 4, 25, 28, 30], 30: [16, 10, 26, 12, 29], 31: [4, 5, 24, 9, 28]}

edit retag flag offensive close merge delete

Comments

1

Try to add parameter layout='spring', run a few times and see it it gives anything you like Drawing will be different each time.

Max Alekseyev gravatar imageMax Alekseyev ( 2023-02-17 17:23:27 +0100 )edit
1

To remove the default vertex positions, try

sage: g1.set_pos({})
sage: g1.show(method='js')
sage: g1.plot()
FrédéricC gravatar imageFrédéricC ( 2023-02-17 20:13:16 +0100 )edit

2 Answers

Sort by » oldest newest most voted
3

answered 2023-02-18 09:15:38 +0100

An answer to this question is in the documentation of the cube graph generator (graphs.CubeGraph?) : use parameter embedding.

g1 = graphs.CubeGraph(5, embedding=2)
g1.relabel()
m = g1.dominating_set()
g1.plot(vertex_colors={"red": m})

image description

edit flag offensive delete link more
1

answered 2023-02-18 04:41:55 +0100

dazedANDconfused gravatar image

updated 2023-02-18 15:08:14 +0100

I use 3 useful tweaks in making graphs: 1. Adjust the vertex size, 2. Adjust the distance between vertices, 3. arrange the vertices around a circle. Try the following code:

g1 = graphs.CubeGraph(5)
g1.relabel()
m=g1.dominating_set()
g1.set_pos(g1.layout_circular())
g1.plot(vertex_colors={"red": m}, vertex_size=400, figsize=[8,8])
  1. was done with vertex_size=400. This allows the labels to fit better. You can, of course, use a larger number. 2. was accomplished with figsize=[8,8] by making the graphic image bigger. 3. is accomplished by g1.set_pos(g1.layout_circular()) to give a circular layout. The result of the code is below:

image description

To make your graphs even nicer, you can use LaTeX. An example can be found here using sagetex combined with Sage and LaTeX to produce the Petersen graph.

edit flag offensive delete link more

Comments

1

The default embedding may assign the same position to 2 vertices, here 12 and 29. However, the generator proposes an alternative embedding that avoids this issue.

David Coudert gravatar imageDavid Coudert ( 2023-02-18 09:20:05 +0100 )edit
1

Thanks, I didn't notice that. I use circular layout when I am not happy with positioning. I've edited my answer to show how.

dazedANDconfused gravatar imagedazedANDconfused ( 2023-02-18 15:10:25 +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: 2023-02-17 13:28:17 +0100

Seen: 243 times

Last updated: Feb 21 '23