Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Plotly · Class

go.Treemap

go.Treemap is a Plotly trace for representing hierarchical data with nested rectangles. Its sectors are defined by labels or IDs, parent relationships, and optionally numeric values.

How it works

Instantiate go.Treemap with hierarchical labels and parent references; optional values determine sector sizes and can be aggregated according to branchvalues. Add the trace to a Figure to render the interactive rectangles.

Syntax

plotly.graph_objects.Treemap(arg=None, alignmentgroup=None, ... , values=None, visible=None, **kwargs)

Parameters

NameTypeDescription
argdict or plotly.graph_objects.TreemapDictionary of properties compatible with this constructor, or an existing Treemap object.
branchvaluesstrControls how values are summed for branch nodes.
labelslistLabels displayed for sectors.
parentslistParent reference for each sector.
valueslistNumeric values used to size sectors.
visiblebool or strWhether to display the trace.

Returns

A plotly.graph_objects.Treemap trace object.

Key points

  • Use the class to display hierarchical data as rectangles, progressing from leaf or outer-branch entries toward a root.
  • Define sectors with labels or ids, and connect them into the hierarchy through parents.
  • The branchvalues property controls the aggregation rule for numeric values across branches.
  • The count property supplies the default value behavior when no values array is given.

Common mistakes

  • Every sector needs a coherent hierarchy: use labels or unique ids together with matching parents entries.
  • Choose branchvalues deliberately because it changes how parent totals relate to descendant values.
  • If values is omitted, Plotly infers defaults rather than treating every sector as having an explicitly supplied measurement.

Example: Basic hierarchical treemap

import plotly.graph_objects as go

fig = go.Figure(go.Treemap(
    labels=["Company", "Engineering", "Sales", "Backend", "Frontend"],
    parents=["", "Company", "Company", "Engineering", "Engineering"],
    values=[100, 60, 40, 35, 25],
))
fig.show()

Creates a hierarchical treemap whose rectangles are defined by labels, parent relationships, and numeric values.

When to use it

Hierarchical quantitative breakdowns

Compare quantities across nested categories.

Part-to-whole exploration

Show how leaf items roll up into branches and a root.

Interactive hierarchy navigation

Build interactive drillable category views in a Plotly figure.

Interview questions

QWhat does go.Treemap represent, and how is its hierarchy specified?

go.Treemap visualizes hierarchical data with nested rectangles. The hierarchy comes from labels or ids plus parents, while values controls the quantitative size of sectors.

Follow-up: How are parent values interpreted? branchvalues determines how values are summed across branches, so it should match whether parent values include descendants.

QWhat are the main constructor inputs?

The constructor accepts a dictionary of compatible properties or another Treemap instance through arg, followed by trace properties such as labels, parents, values, and branchvalues. This lets callers configure the trace directly or from property mappings.

Follow-up: Why might ids be preferable to labels? IDs provide stable sector identity when displayed labels are duplicated or change.

QWhat happens if values is omitted?

When values is not supplied, the class infers a default of 1 for leaves and/or branches and otherwise 0. Explicit values are preferable when rectangle areas must represent measured quantities.

Follow-up: What should be checked when inferred values look unexpected? Inspect whether nodes are leaves or branches and provide an explicit values array when needed.

  • plotly.graph_objects.Figure
  • plotly.graph_objects.Sunburst
  • plotly.graph_objects.Icicle
  • plotly.graph_objects.layout.template.data.Treemap

Source: plotly.graph_objects.Treemap — 6.8.0 documentation. Checked 2026-10-15.