Products
  • Wolfram|One

    The definitive Wolfram Language and notebook experience

  • Mathematica

    The original technical computing environment

  • System Modeler

    Multidomain modeling and simulation of complex systems

  • Compute ServicesUse with Mathematica and Wolfram|One
  • AI AccessUse with Mathematica and Wolfram|One
  • Finance Platform
  • Wolfram|Alpha Notebook Edition
  • Application Server
  • Enterprise Private Cloud
  • Wolfram Engine
  • Wolfram Player
  • Wolfram Cloud App
  • Wolfram Player App

More mobile apps

Wolfram|Alpha

  • Wolfram|Alpha Website
  • Wolfram|Alpha APIs

AI Products

  • Wolfram AI Ecosystem
  • Wolfram Foundation Tool
  • Wolfram Cloud MCP
  • Wolfram Local MCP
  • Agent One API
  • CAG Component APIs

Core Technologies of Wolfram Products

  • Wolfram Language
  • Computable Data
  • Wolfram Notebooks
  • Linguistic Understanding

Additional Deployment Options

  • Wolfram Cloud
  • Wolfram Web Engine
  • wolframscript
  • WSTPServer
  • Group & Organizational Licensing
  • All Products
Consulting & Solutions

We deliver solutions for the AI era—combining symbolic computation, data-driven insights and deep technical expertise

Wolfram Consulting

Data Science, Finance & Business

  • Artificial Intelligence
  • Data Science
  • Healthcare
  • Real Estate

Engineering

  • Civil Engineering
  • Automotive Engineering
  • Sustainable Energy

Science & Technology

  • AgTech
  • Biosciences
  • Environmental Science
  • Food Science
  • Quantum Computation
  • Social and Behavioral Sciences

More Wolfram Solutions

Technology for Education

  • Research Universities
  • Colleges & Teaching Universities
  • High Schools
  • Resources for Students

Education Initiatives

  • Next-Gen EdTech
  • Computer-Based Math

More Solutions for Education

  • Contact Us
Learning & Support

Get Started

  • Wolfram Language Introduction
  • Fast Intro for Programmers
  • Fast Intro for Math Students
  • Wolfram Language Documentation

More Learning

  • Highlighted Core Areas
  • Demonstrations
  • YouTube
  • Daily Study Groups
  • Wolfram Schools and Programs
  • Books

Grow Your Skills

  • Wolfram U

    Courses in computing, science, life and more

  • Community

    Learn, solve problems and share ideas.

  • Blog

    News, views and insights from Wolfram

  • Resources for

    Software Developers

Tech Support

  • Contact Us
  • Support FAQs
  • Support FAQs
  • Contact Us
Company
  • About Wolfram
  • Career Center
  • All Sites & Resources
  • Connect & Follow
  • Contact Us

Work with Us

  • Student Ambassador Initiative
  • Wolfram for Startups
  • Student Opportunities
  • Jobs Using Wolfram Language

Educational Programs for Adults

  • Summer School
  • Winter School

Educational Programs for Youth

  • Middle School Camp
  • High School Research Program
  • Computational Adventures

Read

  • Stephen Wolfram's Writings
  • Wolfram Blog
  • Wolfram Tech | Books
  • Wolfram Media
  • Complex Systems

Educational Resources

  • Wolfram MathWorld
  • Wolfram in STEM
  • Wolfram Challenges
  • Wolfram Problem Generator

Wolfram Initiatives

  • Wolfram Science
  • Wolfram Foundation
  • History of Mathematics Project

Events

  • Stephen Wolfram Livestreams
  • Online & In-Person Events
  • Contact Us
  • Connect & Follow
For AIs
  • Your Account
  • User Portal
  • Wolfram Cloud
  • Products
    • Wolfram|One
    • Mathematica
    • System Modeler
    • Compute ServicesUse with Mathematica and Wolfram|One
    • AI AccessUse with Mathematica and Wolfram|One
    • Finance Platform
    • Wolfram|Alpha Notebook Edition
    • Application Server
    • Enterprise Private Cloud
    • Wolfram Engine
    • Wolfram Player
    • Wolfram Cloud App
    • Wolfram Player App

    More mobile apps

    • Wolfram|Alpha
      • Wolfram|Alpha Website
      • Wolfram|Alpha APIs
    • AI Products
      • Wolfram AI Ecosystem
      • Wolfram Foundation Tool
      • Wolfram Cloud MCP
      • Wolfram Local MCP
      • Agent One API
      • CAG Component APIs
    • Core Technologies
      • Wolfram Language
      • Computable Data
      • Wolfram Notebooks
      • Linguistic Understanding
    • Additional Deployment Options
      • Wolfram Cloud
      • Wolfram Web Engine
      • wolframscript
      • WSTPServer
    • Group & Organizational Licensing
    • All Products
  • Consulting & Solutions
    • Wolfram Consulting

    Data Science, Finance & Business

    • Artificial Intelligence
    • Data Science
    • Healthcare
    • Real Estate

    Engineering

    • Civil Engineering
    • Automotive Engineering
    • Sustainable Energy

    Science & Technology

    • AgTech
    • Biosciences
    • Environmental Science
    • Food Science
    • Quantum Computation
    • Social and Behavioral Sciences

    More Wolfram Solutions

    Technology for Education

    • Research Universities
    • Colleges & Teaching Universities
    • High Schools
    • Resources for Students

    Education Initiatives

    • Next-Gen EdTech
    • Computer-Based Math

    More Solutions for Education

    • Contact Us
  • Learning & Support

    Get Started

    • Wolfram Language Introduction
    • Fast Intro for Programmers
    • Fast Intro for Math Students
    • Wolfram Language Documentation

    Grow Your Skills

    • Wolfram U

      Courses in computing, science, life and more

    • Community

      Learn, solve problems and share ideas.

    • Blog

      News, views and insights from Wolfram

    • Resources for

      Software Developers
    • Tech Support
      • Contact Us
      • Support FAQs
    • More Learning
      • Highlighted Core Areas
      • Demonstrations
      • YouTube
      • Daily Study Groups
      • Wolfram Schools and Programs
      • Books
    • Support FAQs
    • Contact Us
  • Company
    • About Wolfram
    • Career Center
    • All Sites & Resources
    • Connect & Follow
    • Contact Us

    Work with Us

    • Student Ambassador Initiative
    • Wolfram for Startups
    • Student Opportunities
    • Jobs Using Wolfram Language

    Educational Programs for Adults

    • Summer School
    • Winter School

    Educational Programs for Youth

    • Middle School Camp
    • High School Research Program
    • Computational Adventures

    Read

    • Stephen Wolfram's Writings
    • Wolfram Blog
    • Wolfram Tech | Books
    • Wolfram Media
    • Complex Systems
    • Educational Resources
      • Wolfram MathWorld
      • Wolfram in STEM
      • Wolfram Challenges
      • Wolfram Problem Generator
    • Wolfram Initiatives
      • Wolfram Science
      • Wolfram Foundation
      • History of Mathematics Project
    • Events
      • Stephen Wolfram Livestreams
      • Online & In-Person Events
    • Contact Us
    • Connect & Follow
  • For AIs
  • Wolfram Cloud
  • Your Account
  • User Portal
Wolfram Language & System Documentation Center
TreePlot
  • See Also
    • TreeGraph
    • Graph
    • LayeredGraphPlot
    • GraphPlot
    • TreeForm
    • CommunityGraphPlot
    • GraphLayout
    • GraphEmbedding
  • Related Guides
    • Computational Systems
    • Tree Visualization
    • Data Visualization
    • Scientific Data Analysis
    • Graph Visualization
    • Life Sciences & Medicine: Data & Computation
    • Social Network Analysis
    • Graph Layouts
    • Trees
    • See Also
      • TreeGraph
      • Graph
      • LayeredGraphPlot
      • GraphPlot
      • TreeForm
      • CommunityGraphPlot
      • GraphLayout
      • GraphEmbedding
    • Related Guides
      • Computational Systems
      • Tree Visualization
      • Data Visualization
      • Scientific Data Analysis
      • Graph Visualization
      • Life Sciences & Medicine: Data & Computation
      • Social Network Analysis
      • Graph Layouts
      • Trees

TreePlot[g]

generates a tree plot of the graph g.

TreePlot[{e1,e2,…}]

generates a tree plot of the graph with edges ej.

TreePlot[{…,w[ei],…}]

plots ei with features defined by the symbolic wrapper w.

TreePlot[{vi 1vj 1,…}]

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

TreePlot[m]

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

TreePlot[…,vpos]

places the root v in the plot at position pos.

Details and Options
Details and Options Details and Options
Examples  
Basic Examples  
Scope  
Graph Specification  
Graph Styling  
Options  
AspectRatio  
Axes  
AxesLabel  
Show More Show More
AxesOrigin  
AxesStyle  
DataRange  
DirectedEdges  
Frame  
FrameLabel  
FrameStyle  
ImageSize  
LayerSizeFunction  
PlotStyle  
Applications  
Properties & Relations  
Possible Issues  
Neat Examples  
See Also
Related Guides
History
Cite this Page
BUILT-IN SYMBOL
  • See Also
    • TreeGraph
    • Graph
    • LayeredGraphPlot
    • GraphPlot
    • TreeForm
    • CommunityGraphPlot
    • GraphLayout
    • GraphEmbedding
  • Related Guides
    • Computational Systems
    • Tree Visualization
    • Data Visualization
    • Scientific Data Analysis
    • Graph Visualization
    • Life Sciences & Medicine: Data & Computation
    • Social Network Analysis
    • Graph Layouts
    • Trees
    • See Also
      • TreeGraph
      • Graph
      • LayeredGraphPlot
      • GraphPlot
      • TreeForm
      • CommunityGraphPlot
      • GraphLayout
      • GraphEmbedding
    • Related Guides
      • Computational Systems
      • Tree Visualization
      • Data Visualization
      • Scientific Data Analysis
      • Graph Visualization
      • Life Sciences & Medicine: Data & Computation
      • Social Network Analysis
      • Graph Layouts
      • Trees

TreePlot

TreePlot[g]

generates a tree plot of the graph g.

TreePlot[{e1,e2,…}]

generates a tree plot of the graph with edges ej.

TreePlot[{…,w[ei],…}]

plots ei with features defined by the symbolic wrapper w.

TreePlot[{vi 1vj 1,…}]

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

TreePlot[m]

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

TreePlot[…,vpos]

places the root v in the plot at position pos.

Details and Options

  • TreePlot is also known as tree diagram.
  • 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: [List of all options]
  • 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
  • List of all options

    • AlignmentPointCenterthe default point in the graphic to align with
      AspectRatioAutomaticratio of height to width
      AxesFalsewhether to draw axes
      AxesLabelNoneaxes labels
      AxesOriginAutomaticwhere axes should cross
      AxesStyle{}style specifications for the axes
      BackgroundNonebackground color for the plot
      BaselinePositionAutomatichow to align with a surrounding text baseline
      BaseStyle{}base style specifications for the graphic
      ContentSelectableAutomaticwhether to allow contents to be selected
      CoordinatesToolOptionsAutomaticdetailed behavior of the coordinates tool
      DataRangeAutomaticthe range of vertex coordinates to generate
      DirectedEdgesFalsewhether to interpret Rule as DirectedEdge
      EdgeLabelsNonelabels and placements for edges
      EdgeLabelStyleAutomaticstyle to use for edge labels
      EdgeShapeFunctionAutomaticgenerate graphic shapes for edges
      EdgeStyleAutomaticstyles for edges
      Epilog{}primitives rendered after the main plot
      FormatTypeTraditionalFormthe default format type for text
      FrameFalsewhether to put a frame around the plot
      FrameLabelNoneframe labels
      FrameStyle{}style specifications for the frame
      FrameTicksAutomaticframe ticks
      FrameTicksStyle{}style specifications for frame ticks
      GraphHighlight{}vertices and edges to highlight
      GraphHighlightStyleAutomaticstyle for highlight
      GridLinesNonegrid lines to draw
      GridLinesStyle{}style specifications for grid lines
      ImageMargins0.the margins to leave around the graphic
      ImagePaddingAllwhat extra padding to allow for labels etc.
      ImageSizeAutomaticthe absolute size at which to render the graphic
      LabelStyle{}style specifications for labels
      LayerSizeFunction(1)the height to allow for each layer
      MethodAutomaticdetails of graphics methods to use
      PerformanceGoalAutomaticaspects of performance to try to optimize
      PlotLabelNonean overall label for the plot
      PlotRangeAllrange of values to include
      PlotRangeClippingFalsewhether to clip at the plot range
      PlotRangePaddingAutomatichow much to pad the range of values
      PlotRegionAutomaticthe final display region to be filled
      PlotStyleAutomaticgraphics directives to determine styles
      PlotThemeAutomaticoverall theme for the graph
      PreserveImageOptionsAutomaticwhether to preserve image options when displaying new versions of the same graphic
      Prolog{}primitives rendered before the main plot
      RotateLabelTruewhether to rotate y labels on the frame
      TicksAutomaticaxes ticks
      TicksStyle{}style specifications for axes ticks
      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

Examples

open all close all

Basic Examples  (5)

Plot a graph:

Wolfram Language code: TreePlot[KaryTree[9, 2]]

Plot a graph specified by edge rules:

Wolfram Language code: TreePlot[{1 -> 2, 2 -> 3, 3 -> 4, 4 -> 0, 5 -> 1, 6 -> 2, 7 -> 3, 8 -> 4, 9 -> 0}]

Plot a graph specified by its adjacency matrix:

Wolfram Language code: TreePlot[{{0, 1, 1, 1, 0}, {1, 0, 0, 0, 1}, {1, 0, 0, 0, 0}, {1, 0, 0, 0, 0}, {0, 1, 0, 0, 0}}]

Drawing a tree with different orientation from the default:

Wolfram Language code: TreePlot[{1 -> 4, 1 -> 6, 1 -> 8, 2 -> 6, {3 -> 8, "3->8"}, 4 -> 5, 7 -> 8}, Left]

Specify the root node:

Wolfram Language code: Table[TreePlot[{1 -> 4, 1 -> 6, 1 -> 8, 2 -> 6, 3 -> 8, 4 -> 5, 7 -> 8}, Automatic, root, VertexLabels -> Automatic], {root, {1, 5}}]

Scope  (10)

Graph Specification  (4)

Specify a graph using a graph:

Wolfram Language code: TreePlot[Graph[{14, 17, 25, 34, 45, 56}]]

Specify a graph using a rule list:

Wolfram Language code: TreePlot[{1 -> 4, 1 -> 7, 2 -> 5, 3 -> 4, 4 -> 5, 5 -> 6}]

Specify a graph using a dense adjacency matrix:

Wolfram Language code: TreePlot[{{0, 1, 0, 0}, {0, 0, 1, 1}, {0, 0, 0, 0}, {0, 0, 0, 0}}]

Specify a graph using a sparse adjacency matrix:

Wolfram Language code: TreePlot[SparseArray[{{1, 2}, {2, 3}, {2, 4}} -> 1, {4, 4}]]

Graph Styling  (6)

Give labels for some edges:

Wolfram Language code: TreePlot[{1 -> 2, 3 -> 1, Labeled[2 -> 4, "2->4"], 2 -> 5}]

Give vertex labels:

Wolfram Language code: TreePlot[{1 -> 2, 3 -> 1, 2 -> 4, 2 -> 5, 1 -> 2, 5 -> 5, 3 -> 6}, VertexLabels -> Automatic]

Show edges as arrows:

Wolfram Language code: TreePlot[{1 -> 3, 1 -> 5, 2 -> 6, 2 -> 7, 2 -> 8, 4 -> 6, 5 -> 6}, DirectedEdges -> True]

Plot a disconnected graph using different packing methods:

Wolfram Language code: Table[Framed@TreePlot[Table[i -> Mod[i ^ 2, 31], {i, 0, 31}], GraphLayout -> {"PackingLayout" -> pm}], {pm, {Automatic, "ClosestPacking"}}]

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

Wolfram Language code: TreePlot[Table[i -> Mod[i ^ 2, 351], {i, 351}], VertexShapeFunction -> None]

Drawing a tree with different orientations:

Wolfram Language code: Grid[Partition[Table[TreePlot[{1 -> 4, 1 -> 6, 1 -> 8, 2 -> 6, {3 -> 8, "3->8"}, 4 -> 5, 7 -> 8}, pos, BaselinePosition -> Top, PlotLabel -> pos], {pos, {Automatic, Left, Top, Right, Bottom, Center}}], {3}]]

Options  (35)

AspectRatio  (1)

By default, the ratio of the height to width for the plot is determined automatically:

Wolfram Language code: t = Flatten[Table[{i -> 2 i + j - 1}, {j, 2}, {i, 7}]];
Wolfram Language code: TreePlot[t]

AspectRatio1 will make width equal to height:

Wolfram Language code: TreePlot[t, AspectRatio -> 1]

AspectRatioFull adjusts the height and width to tightly fit inside other constructs:

Wolfram Language code: plot = TreePlot[t, AspectRatio -> Full];
Wolfram Language code: {Framed[Pane[plot, {50, 100}]], Framed[Pane[plot, {100, 100}]], Framed[Pane[plot, {100, 50}]]}

Axes  (1)

By default, Axes are not drawn:

Wolfram Language code: t = Flatten[Table[{i -> 2 i + j - 1}, {j, 2}, {i, 7}]];
Wolfram Language code: TreePlot[t]

Use AxesTrue to turn on axes:

Wolfram Language code: TreePlot[t, Axes -> True]

Turn each axis on individually:

Wolfram Language code: {TreePlot[t, Axes -> {True, False}], TreePlot[t, Axes -> {False, True}]}

AxesLabel  (3)

No axes labels are drawn by default:

Wolfram Language code: TreePlot[Flatten[Table[{i -> 2 i + j - 1}, {j, 2}, {i, 7}]], Axes -> True]

Place a label on the axis:

Wolfram Language code: TreePlot[Flatten[Table[{i -> 2 i + j - 1}, {j, 2}, {i, 7}]], Axes -> True, AxesLabel -> y]

Specify axes labels:

Wolfram Language code: TreePlot[Flatten[Table[{i -> 2 i + j - 1}, {j, 2}, {i, 7}]], Axes -> True, AxesLabel -> {x, y}]

AxesOrigin  (2)

The position of the axes is determined automatically:

Wolfram Language code: TreePlot[Flatten[Table[{i -> 2 i + j - 1}, {j, 2}, {i, 7}]], Axes -> True]

Specify an explicit origin for the axes:

Wolfram Language code: TreePlot[Flatten[Table[{i -> 2 i + j - 1}, {j, 2}, {i, 7}]], Axes -> True, AxesOrigin -> {2.5, 3}]

AxesStyle  (4)

Change the style for the axes:

Wolfram Language code: TreePlot[Flatten[Table[{i -> 2 i + j - 1}, {j, 2}, {i, 7}]], Axes -> True, AxesStyle -> Red]

Specify the style of each axis:

Wolfram Language code: TreePlot[Flatten[Table[{i -> 2 i + j - 1}, {j, 2}, {i, 7}]], Axes -> True, AxesStyle -> {{Thick, Red}, {Thick, Blue}}]

Use different styles for the ticks and the axes:

Wolfram Language code: TreePlot[Flatten[Table[{i -> 2 i + j - 1}, {j, 2}, {i, 7}]], Axes -> True, AxesStyle -> Green, TicksStyle -> Red]

Use different styles for the labels and the axes:

Wolfram Language code: TreePlot[Flatten[Table[{i -> 2 i + j - 1}, {j, 2}, {i, 7}]], Axes -> True, AxesStyle -> Green, LabelStyle -> Red]

DataRange  (1)

Specify the range of vertex coordinates:

Wolfram Language code: TreePlot[{1 -> 6, 2 -> 6, 3 -> 6, 4 -> 6, 5 -> 6}, DataRange -> {{0, 1}, {0, 1}}]

DirectedEdges  (1)

Show directed edges:

Wolfram Language code: TreePlot[{1 -> 5, 2 -> 3, 2 -> 4, 3 -> 7, 5 -> 6, 6 -> 7, 6 -> 8}, DirectedEdges -> True]

Frame  (4)

TreePlot does not use a frame by default:

Wolfram Language code: TreePlot[{1 -> 4, 1 -> 7, 2 -> 5, 3 -> 4, 4 -> 5, 5 -> 6}]

Use FrameTrue to draw a frame around the plot:

Wolfram Language code: TreePlot[{1 -> 4, 1 -> 7, 2 -> 5, 3 -> 4, 4 -> 5, 5 -> 6}, Frame -> True]

Draw a frame on the left and right edges:

Wolfram Language code: TreePlot[{1 -> 4, 1 -> 7, 2 -> 5, 3 -> 4, 4 -> 5, 5 -> 6}, Frame -> {{True, True}, {False, False}}]

Draw a frame on the left and bottom edges:

Wolfram Language code: TreePlot[{1 -> 4, 1 -> 7, 2 -> 5, 3 -> 4, 4 -> 5, 5 -> 6}, Frame -> {{True, False}, {True, False}}]

FrameLabel  (4)

Place a label along the bottom frame of the chart:

Wolfram Language code: TreePlot[{1 -> 4, 1 -> 7, 2 -> 5, 3 -> 4, 4 -> 5, 5 -> 6}, Frame -> True, FrameLabel -> {"label"}]

Frame labels are placed on the bottom and left frame edges by default:

Wolfram Language code: TreePlot[{1 -> 4, 1 -> 7, 2 -> 5, 3 -> 4, 4 -> 5, 5 -> 6}, Frame -> True, FrameLabel -> {"bottom", "left"}]

Place labels on each of the edges in the frame:

Wolfram Language code: TreePlot[{1 -> 4, 1 -> 7, 2 -> 5, 3 -> 4, 4 -> 5, 5 -> 6}, Frame -> True, FrameLabel -> {{"left", "right"}, {"bottom", "top"}}]

Use a customized style for both labels and frame tick labels:

Wolfram Language code: TreePlot[{1 -> 4, 1 -> 7, 2 -> 5, 3 -> 4, 4 -> 5, 5 -> 6}, Frame -> True, FrameLabel -> {{"left", "right"}, {"bottom", "top"}}, LabelStyle -> Directive[Bold, Orange]]

FrameStyle  (2)

Specify the style of the frame:

Wolfram Language code: TreePlot[{1 -> 4, 1 -> 7, 2 -> 5, 3 -> 4, 4 -> 5, 5 -> 6}, Frame -> True, FrameStyle -> Directive[StandardGray, Thick]]

Specify the style for each frame edge:

Wolfram Language code: TreePlot[{1 -> 4, 1 -> 7, 2 -> 5, 3 -> 4, 4 -> 5, 5 -> 6}, Frame -> True, FrameStyle -> {{Directive[Green, Thick], Red}, {Directive[Gray, Thick], Blue}}]

ImageSize  (7)

Use named sizes such as Tiny, Small, Medium and Large:

Wolfram Language code: {TreePlot[Flatten[Table[{i -> 2 i + j - 1}, {j, 2}, {i, 7}]], ImageSize -> Tiny], TreePlot[Flatten[Table[{i -> 2 i + j - 1}, {j, 2}, {i, 7}]], ImageSize -> Small]}

Specify the width of the plot:

Wolfram Language code: {TreePlot[Flatten[Table[{i -> 2 i + j - 1}, {j, 2}, {i, 7}]], ImageSize -> 150], TreePlot[Flatten[Table[{i -> 2 i + j - 1}, {j, 2}, {i, 7}]], AspectRatio -> 1, ImageSize -> 150]}

Specify the height of the plot:

Wolfram Language code: {TreePlot[Flatten[Table[{i -> 2 i + j - 1}, {j, 2}, {i, 7}]], ImageSize -> {Automatic, 150}], TreePlot[Flatten[Table[{i -> 2 i + j - 1}, {j, 2}, {i, 7}]], AspectRatio -> 2, ImageSize -> {Automatic, 150}]}

Allow the width and height to be up to a certain size:

Wolfram Language code: {TreePlot[Flatten[Table[{i -> 2 i + j - 1}, {j, 2}, {i, 7}]], ImageSize -> UpTo[200]], TreePlot[Flatten[Table[{i -> 2 i + j - 1}, {j, 2}, {i, 7}]], AspectRatio -> 2, ImageSize -> UpTo[200]]}

Specify the width and height for a graphic, padding with space if necessary:

Wolfram Language code: TreePlot[Flatten[Table[{i -> 2 i + j - 1}, {j, 2}, {i, 7}]], ImageSize -> {200, 200}, Background -> LightBlue]

Setting AspectRatioFull will fill the available space:

Wolfram Language code: TreePlot[Flatten[Table[{i -> 2 i + j - 1}, {j, 2}, {i, 7}]], AspectRatio -> Full, ImageSize -> {200, 200}, Background -> LightBlue]

Use maximum sizes for the width and height:

Wolfram Language code: {TreePlot[Flatten[Table[{i -> 2 i + j - 1}, {j, 2}, {i, 7}]], ImageSize -> {UpTo[150], UpTo[100]}], TreePlot[Flatten[Table[{i -> 2 i + j - 1}, {j, 2}, {i, 7}]], AspectRatio -> 2, ImageSize -> {UpTo[150], UpTo[100]}]}

Use ImageSizeFull to fill the available space in an object:

Wolfram Language code: Framed[Pane[TreePlot[Flatten[Table[{i -> 2 i + j - 1}, {j, 2}, {i, 7}]], ImageSize -> Full, Background -> LightBlue], {200, 100}]]

Specify the image size as a fraction of the available space:

Wolfram Language code: Framed[Pane[TreePlot[Flatten[Table[{i -> 2 i + j - 1}, {j, 2}, {i, 7}]], AspectRatio -> Full, ImageSize -> {Scaled[0.5], Scaled[0.5]}, Background -> LightBlue], {200, 100}]]

LayerSizeFunction  (2)

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

Wolfram Language code: TreePlot[{1 -> 2, 1 -> 3, 2 -> 4, 2 -> 5, 3 -> 6, 3 -> 7}, LayerSizeFunction -> (#&)]

Plot a binary tree with random layer size:

Wolfram Language code: TreePlot[Flatten[Table[{i -> 2i + j - 1}, {j, 2}, {i, 2 ^ 7 - 1}]], Center, LayerSizeFunction -> (RandomReal[{-4, 4}]&)]

PlotStyle  (3)

Specify an overall style for the graph:

Wolfram Language code: Table[TreePlot[{1 -> 3, 1 -> 5, 1 -> 6, 1 -> 7, 2 -> 3, 4 -> 5, 5 -> 8}, PlotStyle -> ps], {ps, {Red, Dashed, Directive[Red, Dashed]}}]

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

Wolfram Language code: TreePlot[{1 -> 3, 1 -> 5, 1 -> 6, 1 -> 7, 2 -> 3, 4 -> 5, 5 -> 8}, PlotStyle -> Directive[PointSize[Large], Red], VertexShapeFunction -> Function[{p, l}, {Green, Point[p]}]]

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

Wolfram Language code: TreePlot[{1 -> 3, 1 -> 5, 1 -> 6, 1 -> 7, 2 -> 3, 4 -> 5, 5 -> 8}, PlotStyle -> Directive[Dashed, Red], EdgeShapeFunction -> Function[{p, vl}, {Green, Line[p]}]]

Applications  (8)

Define a complete binary tree of depth 3:

Wolfram Language code: t = Flatten[Table[{i -> 2i + j - 1}, {j, 2}, {i, 7}]]

Use different tree layouts:

Wolfram Language code: Table[TreePlot[t, p], {p, {Top, Left, Bottom, Right, Center}}]

Draw a -ary tree:

Wolfram Language code: TreePlot[KaryTree[40, 3], Center]

Generate and plot a random tree:

Wolfram Language code: TreePlot[RandomInteger[#] -> # + 1 & /@ Range[0, 30]]

Delete random connections in a binary tree:

Wolfram Language code: TreePlot[Delete[Flatten[Table[{i -> 2i + j - 1}, {j, 2}, {i, 100}]], List /@ RandomInteger[{1, 100}, {40}]]]

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

Wolfram Language code: TreePlot[Table[j -> FromDigits[RotateRight[IntegerDigits[j, 2]], 2], {j, 0, 2 ^ 8 - 1}], Center]

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

Wolfram Language code: TreePlot[Table[j -> FromDigits[RotateLeft[IntegerDigits[j, 2]], 2], {j, 0, 2 ^ 6 - 1}]]

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

Wolfram Language code: TreePlot[Table[j -> FromDigits[Drop[IntegerDigits[j, 2], -1], 2], {j, 0, 2 ^ 8 - 1}], Center]

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

Wolfram Language code: TreePlot[Table[j -> FromDigits[Drop[IntegerDigits[j, 2], 1], 2], {j, 0, 2 ^ 6 - 1}]]

Properties & Relations  (4)

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

Wolfram Language code: TreePlot[{1 -> 2, 2 -> 3, 3 -> 4, 4 -> 1, 3 -> 5, 1 -> 2, 5 -> 5}]

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

Wolfram Language code: Table[pt[{1 -> 4, 1 -> 6, 1 -> 8, 2 -> 6, 3 -> 8, 4 -> 5, 7 -> 8}, PlotLabel -> pt, DirectedEdges -> True, PlotTheme -> "DiagramBlue"], {pt, {TreePlot, LayeredGraphPlot}}]

Use GraphPlot or GraphPlot3D for general undirected graph drawing:

Wolfram Language code: g = {1 -> 2, 1 -> 6, 1 -> 20, 2 -> 3, 2 -> 17, 3 -> 4, 3 -> 12, 4 -> 5, 4 -> 15, 5 -> 6, 5 -> 10, 6 -> 7, 7 -> 8, 7 -> 16, 8 -> 9, 8 -> 19, 9 -> 10, 9 -> 14, 10 -> 11, 11 -> 12, 11 -> 20, 12 -> 13, 13 -> 14, 13 -> 18, 14 -> 15, 15 -> 16, 16 -> 17, 17 -> 18, 18 -> 19, 19 -> 20};
Wolfram Language code: {GraphPlot[g], GraphPlot3D[g]}

Use ArrayPlot or MatrixPlot to display sparse matrices:

Wolfram Language code: g = ExampleData[{"Matrix", "Bai/bfwa62"}, "Matrix"]
Wolfram Language code: {ArrayPlot[g], MatrixPlot[g]}

Possible Issues  (2)

For nontree graphs, edges may overlap:

Wolfram Language code: TreePlot[{1 -> 2, 1 -> 3, 1 -> 4, 2 -> 3, 2 -> 4, 3 -> 4}, VertexLabels -> Automatic]

Use LayeredGraphPlot or GraphPlot to avoid overlapping edges:

Wolfram Language code: LayeredGraphPlot[{1 -> 2, 1 -> 3, 1 -> 4, 2 -> 3, 2 -> 4, 3 -> 4}, VertexLabels -> Automatic]
Wolfram Language code: GraphPlot[{1 -> 2, 1 -> 3, 1 -> 4, 2 -> 3, 2 -> 4, 3 -> 4}, VertexLabels -> Automatic]

TreePlot automatically chooses the base node to minimize tree height:

Wolfram Language code: TreePlot[{1 -> 2, 2 -> 3}, PlotTheme -> "DiagramGreen"]

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

Wolfram Language code: TreePlot[{1 -> 2, 2 -> 3}, Top, 1, PlotTheme -> "DiagramGreen"]

Neat Examples  (1)

Complete binary trees with random layer layout sizes:

Wolfram Language code: Table[TreePlot[Flatten[Table[{i -> 2i + j - 1}, {j, 2}, {i, 2 ^ 7 - 1}]], Center, LayerSizeFunction -> (RandomReal[{-4, 4}]&)], {6}]

See Also

TreeGraph  Graph  LayeredGraphPlot  GraphPlot  TreeForm  CommunityGraphPlot  GraphLayout  GraphEmbedding

Function Repository: GenealogyTreePlot

Related Guides

    ▪
  • Computational Systems
  • ▪
  • Tree Visualization
  • ▪
  • Data Visualization
  • ▪
  • Scientific Data Analysis
  • ▪
  • Graph Visualization
  • ▪
  • Life Sciences & Medicine: Data & Computation
  • ▪
  • Social Network Analysis
  • ▪
  • Graph Layouts
  • ▪
  • Trees

History

Introduced in 2007 (6.0) | Updated in 2019 (12.0) ▪ 2020 (12.1)

Wolfram Research (2007), TreePlot, Wolfram Language function, https://reference.wolfram.com/language/ref/TreePlot.html (updated 2020).

Text

Wolfram Research (2007), TreePlot, Wolfram Language function, https://reference.wolfram.com/language/ref/TreePlot.html (updated 2020).

CMS

Wolfram Language. 2007. "TreePlot." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/TreePlot.html.

APA

Wolfram Language. (2007). TreePlot. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TreePlot.html

BibTeX

@misc{reference.wolfram_2026_treeplot, author="Wolfram Research", title="{TreePlot}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/TreePlot.html}", note=[Accessed: 01-September-2026]}

BibLaTeX

@online{reference.wolfram_2026_treeplot, organization={Wolfram Research}, title={TreePlot}, year={2020}, url={https://reference.wolfram.com/language/ref/TreePlot.html}, note=[Accessed: 01-September-2026]}

Top
Introduction for Programmers
Introductory Book
Wolfram Function Repository | Wolfram Data Repository | Wolfram Data Drop | Wolfram Language Products
Top
  • Products
  • Wolfram|One
  • Mathematica
  • AI Access
  • Compute Services
  • System Modeler

  • Wolfram|Alpha Notebook Edition
  • Wolfram|Alpha Pro
  • Mobile Apps

  • Wolfram Engine
  • Wolfram Player

  • Volume & Site Licensing
  • Server Deployment Options
  • Consulting
  • Wolfram Consulting
  • Repositories
  • Data Repository
  • Function Repository
  • Community Paclet Repository
  • Neural Net Repository
  • Prompt Repository

  • Wolfram Language Example Repository
  • Notebook Archive
  • Wolfram GitHub
  • Learning
  • Wolfram U
  • Wolfram Language Documentation
  • Webinars & Training
  • Educational Programs

  • Wolfram Language Introduction
  • Fast Introduction for Programmers
  • Fast Introduction for Math Students
  • Books

  • Wolfram Community
  • Wolfram Blog
  • Public Resources
  • Wolfram|Alpha
  • Wolfram Problem Generator
  • Wolfram Challenges

  • Computer-Based Math
  • Computational Thinking
  • Computational Adventures

  • Demonstrations Project
  • Wolfram Data Drop
  • MathWorld
  • Wolfram Science
  • Wolfram Media Publishing
  • Customer Resources
  • Store
  • Product Downloads
  • User Portal
  • Your Account
  • Organization Access

  • Support FAQ
  • Contact Support
  • Company
  • About Wolfram
  • Careers
  • Contact
  • Events
Wolfram Community Wolfram Blog
Legal & Privacy Policy
WolframAlpha.com | WolframCloud.com
© 2026 Wolfram
© 2026 Wolfram | Legal & Privacy Policy |
English