
Methods


The layout styles supported for displaying a graph are none, default, user, fixed, bipartite, circle, grid, network, planar, random, spectral, spring, and tree.

fixed


•

The layout fixed specifies that point positions stored with a special graph (see SpecialGraphs) should be used. If there are no stored points on the graph, DrawGraph will issue an error.

>

G1 := GraphTheory:SpecialGraphs:PetersenGraph();

${\mathrm{G1}}{\u2254}{\mathrm{Graph\; 1:\; an\; undirected\; unweighted\; graph\; with\; 10\; vertices\; and\; 15\; edge(s)}}$
 (1) 
>

GraphTheory:DrawGraph(G1, layout=fixed);

>

GraphTheory:DrawGraph(GraphTheory:RandomGraphs:RandomGraph(5,7), layout=fixed);



user


•

The layout user is a not a method but just a directive to retrieve a userspecified layout stored on the graph with the command GraphTheory:SetVertexPositions. If there are no userstored points on the graph, DrawGraph will issue an error.

>

GraphTheory:DrawGraph(G1, layout=user);

>

GraphTheory:SetVertexPositions(G1, [[0, 0], [0.25, 0], [0.5, 0], [.75, 0], [0, .25], [.25, .25], [0.5, .25], [.75, .25], [.25, .5], [0.5, .5]]);

>

GraphTheory:DrawGraph(G1, layout=user);



default


•

Specifying the layout default will cause DrawGraph to ignore any user or fixed layouts stored on the graph, and layout the graph by decomposing it into connected components and choosing layout method for each.

•

For animations, and three dimensions, the default method is always spring. For two dimensions, the layout algorithm first checks if the graph is a tree, then checks if it is a bipartite graph, and if it is neither, the graph will be laid out with the circle layout.

>

GraphTheory:DrawGraph(G1, layout=default);



none


•

The layout none is the same as not specifying a layout at all. So, by default, it will look for a userspecified layout, then look for a fixed layout (these are sometimes stored with special graphs), then, if it fails to find either of those, will execute the default layout.

>

GraphTheory:DrawGraph(G1, layout=none);



bipartite


•

This only works on graphs for which IsBipartite returns true. In that case, it lays out the graph in two columns. It only works in two dimensions.

>

GraphTheory:DrawGraph(G1, layout=bipartite);

>

G2 := GraphTheory:CompleteGraph(3,2);

${\mathrm{G2}}{\u2254}{\mathrm{Graph\; 2:\; an\; undirected\; unweighted\; graph\; with\; 5\; vertices\; and\; 6\; edge(s)}}$
 (2) 
>

GraphTheory:DrawGraph(G2, layout=bipartite);



circle


•

This works for any graph. It lays out the vertices on the edge of a circle in order. It only works in two dimensions. See GraphTheory/Layouts/Circle for options.

>

GraphTheory:DrawGraph(G1, layout=circle);



grid


•

This works for any graph. It lays out the vertices in a regular grid, as close to a square or cube as possible. See GraphTheory/Layouts/Grid for options.

>

GraphTheory:DrawGraph(G1, layout=grid);



interactive


•

This works for any 2D graph. It creates an interactive plot component where the vertices of the graph can be manually positioned. The interactively set layout is stored as the user layout. See GraphTheory/Layouts/Interactive for options.



network


•

This only works for directed graphs that are networks. It lays out the vertices in flow order from sources to sinks. See GraphTheory/Layouts/Network for options.

>

GraphTheory:DrawNetwork(G1, layout=network);

>

N := GraphTheory:Digraph({[1,2],[1,3],[2,4],[3,4]});

${N}{\u2254}{\mathrm{Graph\; 3:\; a\; directed\; unweighted\; graph\; with\; 4\; vertices\; and\; 4\; arc(s)}}$
 (3) 
>

GraphTheory:DrawNetwork(N, layout=network);



planar


•

This only works on planar graphs and uses the same layout as DrawPlanar. It only works in two dimensions.

>

GraphTheory:DrawGraph(G1, layout=planar);

>

GraphTheory:DrawGraph(G2, layout=planar);



random


•

This works for any graph. Random locations are chosen for vertices in the specified dimension. The randomization can be controlled with layout options. See GraphTheory/Layouts/Random for details.

>

GraphTheory:DrawGraph(G1, layout=random);



spectral


•

This works for any graph. Positions are chosen for the vertices from the eigenvectors of the Laplacian matrix of the graph. GraphTheory/Layouts/Spectral for supported options and more details.

>

GraphTheory:DrawGraph(G1, layout=spectral);



spring


•

This works for any graph, and is the only layout method that can generate animations. The layout spring[constant] can be used for a shortcut to layout=spring, layoutoptions=[constantonly=true]. This layout method supports many options. See GraphTheory/Layouts/Spring for the details.

>

GraphTheory:DrawGraph(G1, layout=spring);



tree


•

This works for any graph. It lays out the graph with the root node at the top center, and then recursively lays out the branches. If the graph (digraph) is not a tree (arborescence), the spanning tree (spanning tree of the underlying graph) will be used for the layout.

>

GraphTheory:DrawGraph(G1, layout=tree);

>

GraphTheory:DrawGraph(N, layout=tree);




