# Plotting graph in sage

Is there a way to plot a (graph theory) graph in sage in such a way that physical distance between vertices is at least a threshold (say 1cm)?

Graph layouts should be the way to do it. I am looking for a solution which is not very complicated.

Context: I need to plot a cubic planar graph. The planar layout provided by sage is not very satisfactory (spring layout gives better planar drawings)

Thank you

• Please provide code to produce the graph you are interested in plotting. This will make it easier for others to come up with relevant answers to your question. Jun 4, 2019 at 14:43
• @SamuelLelièvre I would be interested in a general approach towards it. I think plotting a graph without vertices overlapping is a basic functionality. Jun 5, 2019 at 3:52

One of the options for plotting graphs is the circular layout, which is a way to space out vertices consistently.

sage: G = graphs.CubeGraph(4)
sage: G
4-Cube: Graph on 16 vertices
sage: G.plot(layout='circular')
Launched png viewer for Graphics object consisting of 49 graphics primitives


Other options are documented in the documentation which can be accessed by:

sage: G.plot?


One can also show the graph using javascript:

sage: G.show(method='js')


Note that one can also set the positions of the vertices explicitly, see the set_pos method of graphs.

For more on set_pos and all graph plotting topics:

• Thank you very much for pointing out G.plot? Jun 5, 2019 at 6:31