generates a tree plot of the graph g.


generates a tree plot of the graph with edges ej.


plots ei with features defined by the symbolic wrapper w.

TreePlot[{vi 1vj 1,}]

uses rules vi 1vj 1 to specify the graph g.


generates a tree plot of the graph represented by the adjacency matrix m.


places the root v in the plot at position pos.

Details and Options

  • TreePlot attempts to place vertices in a tree of successive layers, or a collection of trees.
  • TreePlot supports the same vertices and edges as Graph.
  • If the graph g is not a tree, TreePlot lays out its vertices on the basis of a spanning tree of each connected component of the graph.
  • TreePlot[g] attempts to choose the root so as to make trees have as few layers as possible.
  • TreePlot[g,pos] places the roots at position pos.
  • Possible positions pos are: Top, Bottom, Left, Right, Center.
  • By default, TreePlot places each tree root at the top.
  • The following special wrappers can be used for the edges ei:
  • Annotation[ei,label]provide an annotation
    Button[ei,action]define an action to execute when the element is clicked
    EventHandler[ei,]define a general event handler for the element
    Hyperlink[ei,uri]make the element act as a hyperlink
    Labeled[ei,]display the element with labeling
    PopupWindow[ei,cont]attach a popup window to the element
    StatusArea[ei,label]display in the status area when the element is moused over
    Style[ei,opts]show the element using the specified styles
    Tooltip[ei,label]attach an arbitrary tooltip to the element
  • TreePlot has the same options as Graphics, with the following additions and changes:
  • DataRange Automaticthe range of vertex coordinates to generate
    DirectedEdges Falsewhether to interpret Rule as DirectedEdge
    EdgeLabelsNonelabels and placements for edges
    EdgeLabelStyleAutomaticstyle to use for edge labels
    EdgeShapeFunctionAutomaticgenerate graphic shapes for edges
    EdgeStyleAutomaticstyles for edges
    GraphHighlight{}vertices and edges to highlight
    GraphHighlightStyleAutomaticstyle for highlight
    LayerSizeFunction (1)the height to allow for each layer
    PerformanceGoalAutomaticaspects of performance to try to optimize
    PlotStyle Automaticgraphics directives to determine styles
    PlotThemeAutomaticoverall theme for the graph
    VertexCoordinatesAutomaticcoordinates for vertices
    VertexLabelsNonelabels and placements for vertices
    VertexLabelStyleAutomaticstyle to use for vertex labels
    VertexShapeAutomaticgraphic shape for vertices
    VertexShapeFunctionAutomaticgenerate graphic shapes for vertices
    VertexSizeAutomaticsize of vertices
    VertexStyleAutomaticstyles for vertices
  • Possible settings for PlotTheme include common base themes:
  • "Business"a bright, modern look appropriate for business presentations or infographics
    "Detailed"identify data by employing labels and tooltips
    "Marketing"elegant, eye-catching design suitable for marketing needs
    "Minimal"simple graph
    "Monochrome"single-color design
    "Scientific"candid design useful for analyzing detailed data with labels and tooltips
    "Web"clean, bold design suitable for a consumer website or blog
    "Classic"historical design of graph to remain compatible with existing uses
  • Graph feature themes affect the plots of vertices and edges. Feature themes include:
  • "LargeGraph"large graph
    "ClassicLabeled"classic graph
    "IndexLabeled"index-labeled graph


open allclose all

Basic Examples  (5)

Plot a graph:

Plot a graph specified by edge rules:

Plot a graph specified by its adjacency matrix:

Drawing a tree with different orientation from the default:

Specify the root node:

Scope  (10)

Graph Specification  (4)

Specify a graph using a graph:

Specify a graph using a rule list:

Specify a graph using a dense adjacency matrix:

Specify a graph using a sparse adjacency matrix:

Graph Styling  (6)

Give labels for some edges:

Give vertex labels:

Show edges as arrows:

Plot a disconnected graph using different packing methods:

For large graphs, it is sometimes better not to draw vertices at all:

Drawing a tree with different orientations:

Options  (7)

DataRange  (1)

Specify the range of vertex coordinates:

DirectedEdges  (1)

Show directed edges:

LayerSizeFunction  (2)

Draw a tree with the first level of height 1, the second level 2, etc.:

Plot a binary tree with random layer size:

PlotStyle  (3)

Specify an overall style for the graph:

PlotStyle can be combined with VertexShapeFunction, which has higher priority:

PlotStyle can be combined with EdgeShapeFunction, which has higher priority:

Applications  (8)

Define a complete binary tree of depth 3:

Use different tree layouts:

Draw a -ary tree:

Generate and plot a random tree:

Delete random connections in a binary tree:

Link a number with one that is rotated one bit right:

Link a number with one that is rotated one bit left:

Link a number with itself but with the last bit dropped:

Link a number with itself but with the first bit dropped:

Properties & Relations  (4)

If the graph is not a tree, it is laid out based on a spanning tree of this graph:

Use LayeredGraphPlot for hierarchical-style drawing of a directed graph:

Use GraphPlot or GraphPlot3D for general undirected graph drawing:

Use ArrayPlot or MatrixPlot to display sparse matrices:

Possible Issues  (2)

For nontree graphs, edges may overlap:

Use LayeredGraphPlot or GraphPlot to avoid overlapping edges:

TreePlot automatically chooses the base node to minimize tree height:

Explicitly specify a top node, which in this case is also the root node:

Neat Examples  (1)

Complete binary trees with random layer layout sizes:

Wolfram Research (2007), TreePlot, Wolfram Language function, (updated 2020).


Wolfram Research (2007), TreePlot, Wolfram Language function, (updated 2020).


Wolfram Language. 2007. "TreePlot." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020.


Wolfram Language. (2007). TreePlot. Wolfram Language & System Documentation Center. Retrieved from


@misc{reference.wolfram_2022_treeplot, author="Wolfram Research", title="{TreePlot}", year="2020", howpublished="\url{}", note=[Accessed: 10-June-2023 ]}


@online{reference.wolfram_2022_treeplot, organization={Wolfram Research}, title={TreePlot}, year={2020}, url={}, note=[Accessed: 10-June-2023 ]}