Graph Layout Methods - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim

Graph Layout Methods


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



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();

G1Graph 1: an undirected graph with 10 vertices and 15 edge(s)


GraphTheory:-DrawGraph(G1, layout=fixed);

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

Error, (in GraphTheory:-DrawGraph) no points found for layout style draw-pos-fixed for this graph



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

GraphTheory:-DrawGraph(G1, layout=user);

Error, (in GraphTheory:-DrawGraph) no points found for layout style draw-pos-user for this graph

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



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



The layout none is the same as not specifying a layout at all.  So, by default, it will look for a user-specified 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);



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

Error, (in GraphTheory:-DrawGraph) input graph is not bipartite

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

G2Graph 2: an undirected graph with 5 vertices and 6 edge(s)


GraphTheory:-DrawGraph(G2, layout=bipartite);



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



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



This works for any 2-D 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.



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

Error, (in GraphTheory:-DrawGraph) graph is not a network

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

NGraph 3: a directed graph with 4 vertices and 4 arc(s)


GraphTheory:-DrawNetwork(N, layout=network);



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

GraphTheory:-DrawGraph(G1, layout=planar);

Error, (in GraphTheory:-DrawGraph) input graph is not planar

GraphTheory:-DrawGraph(G2, layout=planar);



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



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



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



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

See Also