GraphTheory - Maple Programming Help

Home : Support : Online Help : Mathematics : Discrete Mathematics : Graph Theory : GraphTheory Package : GraphTheory/DrawGraph

GraphTheory

 DrawGraph
 draw a graph stored in the Graph data structure

 Calling Sequence DrawGraph(G) DrawGraph(G, style=s) DrawGraph(G, style=tree, root=v) DrawGraph(G, dimension=d) DrawGraph(G, style=spring) DrawGraph(G, style=spring, redraw) DrawGraph(G, style=spring[constant]) DrawGraph(L, options)

Parameters

 G - graph s - (optional) circle, tree, bipartite, spring, planar v - (optional) name of the root vertex d - (optional) integer 2 or 3 L - list or set of graphs

Description

 • DrawGraph displays the vertices and edges of a graph G as a Maple plot. If G has fewer than 100 vertices, the vertex labels are also displayed. If G is a weighted graph with fewer than 46 edges then the edge weights are displayed.
 • The style option forces DrawGraph to display the input graph in a specific style. There are five different styles supported for displaying a graph: circle, tree, bipartite, spring, and planar. All components of a disconnected graph are detected and are displayed separately.  The type of each graph or a component of a disconnected graph is distinguished and is displayed accordingly.
 • The display of vertex labels may be forced or suppressed with the option showlabels=true and showlabels=false, respectively.
 • The display of edge weights may be forced or suppressed with the option showweights=true and showweights=false, respectively.
 • If the style=tree drawing option is specified then the additional optional argument root=v may be specified to specify the root vertex v.
 • The spring option is so named because it simulates a physical model where the vertices are are modeled as protons repelling each other and the edges are modeled as springs attracting adjacent vertices. This leads to a dense system of nonlinear ODEs to be solved and so this option becomes quite expensive beyond 100 vertices. At this time the code for the spring option requires that the graph be connected and it does not display edge weights in 3 dimensions.
 • The spring[constant] style uses a pure constant repulsive force for the vertices. This style is equivalent to spring for Maple 15 and earlier versions. The default is a combined model that initially integrates the ODE using a constant force model, then shifts to use of an inverse square law repulsive force. redraw : redraw the graph using a different random starting position animate=true : create a 50 frame animation of the model
 • By default, the vertex positions for paths, cycles, cliques and most of the graphs in the SpecialGraphs, such as the Petersen graph, have been predefined, so that when displayed, they appear as they would in a textbook.  You may specify the vertex positions for the display of a graph using the SetVertexPositions command.
 • By default, all vertices are yellow and all edges are blue. You may set individual vertex and edge colors using the HighlightVertex and HighlightEdges commands.  You may set vertex and edge colors of a subgraph of G using the HighlightSubgraph command, and set edge colors of a trail, path or cycle of G using the HighlightTrail command.
 • If the input is a set or list of graphs, then the graphs are displayed in a Matrix format, where any left-over cells are simply displayed as empty. The number of graphs to display horizontally is chosen as a value between 2 and 4 determined by the number of graphs in the input list. This can be overridden by providing the width option to tell DrawGraph the number of graphs to display horizontally. For example, specifying width=1 will cause the graphs to be displayed in one long vertical band, and specifying width=nops(L) will cause the graphs to be displayed in one wide horizontal band.

Examples

 > $\mathrm{with}\left(\mathrm{GraphTheory}\right):$
 > $\mathrm{with}\left(\mathrm{SpecialGraphs}\right):$
 > $\mathrm{with}\left(\mathrm{RandomGraphs}\right):$
 > $G≔\mathrm{Graph}\left(\mathrm{undirected},\left\{\left\{1,2\right\},\left\{2,3\right\},\left\{3,4\right\},\left\{4,1\right\}\right\}\right)$
 ${G}{≔}{\mathrm{Graph 1: an undirected unweighted graph with 4 vertices and 4 edge\left(s\right)}}$ (1)
 > $\mathrm{DrawGraph}\left(G\right)$
 > $F≔\mathrm{Graph}\left(6,\mathrm{undirected},\left\{\left\{1,2\right\},\left\{2,3\right\},\left\{5,6\right\}\right\}\right)$
 ${F}{≔}{\mathrm{Graph 2: an undirected unweighted graph with 6 vertices and 3 edge\left(s\right)}}$ (2)
 > $\mathrm{DrawGraph}\left(F\right)$
 > $C≔\mathrm{Graph}\left(\mathrm{directed},\left\{\left[1,2\right],\left[2,3\right],\left[3,4\right],\left[4,1\right]\right\}\right)$
 ${C}{≔}{\mathrm{Graph 3: a directed unweighted graph with 4 vertices and 4 arc\left(s\right)}}$ (3)
 > $\mathrm{DrawGraph}\left(C\right)$
 > $\mathrm{DrawGraph}\left(C,\mathrm{style}=\mathrm{circle}\right)$
 > $W≔\mathrm{Matrix}\left(\left[\left[0,2,3,1\right],\left[2,0,4,1\right],\left[3,4,0,5\right],\left[6,2,5,0\right]\right]\right)$
 ${W}{≔}\left[\begin{array}{rrrr}{0}& {2}& {3}& {1}\\ {2}& {0}& {4}& {1}\\ {3}& {4}& {0}& {5}\\ {6}& {2}& {5}& {0}\end{array}\right]$ (4)
 > $G≔\mathrm{Graph}\left(\mathrm{directed},\mathrm{weighted},W\right)$
 ${G}{≔}{\mathrm{Graph 4: a directed weighted graph with 4 vertices and 12 arc\left(s\right)}}$ (5)
 > $\mathrm{DrawGraph}\left(G\right)$
 > $\mathrm{K33}≔\mathrm{CompleteGraph}\left(3,3\right)$
 ${\mathrm{K33}}{≔}{\mathrm{Graph 5: an undirected unweighted graph with 6 vertices and 9 edge\left(s\right)}}$ (6)
 > $\mathrm{DrawGraph}\left(\mathrm{K33},\mathrm{style}=\mathrm{bipartite}\right)$
 > $T≔\mathrm{SpanningTree}\left(\mathrm{K33}\right)$
 ${T}{≔}{\mathrm{Graph 6: an undirected unweighted graph with 6 vertices and 5 edge\left(s\right)}}$ (7)
 > $\mathrm{DrawGraph}\left(T,\mathrm{style}=\mathrm{tree},\mathrm{root}=2\right)$
 > $\mathrm{HighlightEdges}\left(\mathrm{K33},T,\mathrm{red}\right)$
 > $\mathrm{DrawGraph}\left(\mathrm{K33}\right)$
 > $P≔\mathrm{PetersenGraph}\left(\right)$
 ${P}{≔}{\mathrm{Graph 7: an undirected unweighted graph with 10 vertices and 15 edge\left(s\right)}}$ (8)
 > $\mathrm{DrawGraph}\left(P\right)$
 > $\mathrm{DrawGraph}\left(P,\mathrm{style}=\mathrm{spring}\right)$
 > $\mathrm{DrawGraph}\left(P,\mathrm{style}=\mathrm{spring},\mathrm{redraw}\right)$

To play the following animation in this help page, right-click (Control-click, on Macintosh) the plot to display the context menu.  Select Animation > Play.

 > $\mathrm{DrawGraph}\left(P,\mathrm{style}=\mathrm{spring},\mathrm{animate}=\mathrm{true}\right)$

The commands to create the plots from the Plotting Guide are

 > $H≔\mathrm{HypercubeGraph}\left(3\right)$
 ${H}{≔}{\mathrm{Graph 8: an undirected unweighted graph with 8 vertices and 12 edge\left(s\right)}}$ (9)
 > $\mathrm{DrawGraph}\left(H\right)$
 > $\mathrm{DrawGraph}\left(H,\mathrm{style}=\mathrm{spring},\mathrm{dimension}=3\right)$
 > $\mathrm{IsHamiltonian}\left(H,'\mathrm{cycle}'\right)$
 ${\mathrm{true}}$ (10)
 > $\mathrm{cycle}$
 $\left[{"000"}{,}{"100"}{,}{"110"}{,}{"010"}{,}{"011"}{,}{"111"}{,}{"101"}{,}{"001"}{,}{"000"}\right]$ (11)
 > $\mathrm{HighlightTrail}\left(H,\mathrm{cycle},\mathrm{red}\right)$
 > $\mathrm{DrawGraph}\left(H\right)$
 > $T≔\mathrm{RandomTree}\left(100\right)$
 ${T}{≔}{\mathrm{Graph 9: an undirected unweighted graph with 100 vertices and 99 edge\left(s\right)}}$ (12)
 > $\mathrm{DrawGraph}\left(T\right)$
 > $S≔\mathrm{SoccerBallGraph}\left(\right)$
 ${S}{≔}{\mathrm{Graph 10: an undirected unweighted graph with 60 vertices and 90 edge\left(s\right)}}$ (13)
 > $\mathrm{DrawGraph}\left(S\right)$
 > $\mathrm{DrawGraph}\left(S,\mathrm{style}=\mathrm{spring},\mathrm{dimension}=3\right)$