Treemap
Overview
The treemap
trace type is used to create treemap charts, which visualize hierarchical data through nested rectangles. Each branch of the hierarchy is represented as a rectangle, with smaller rectangles inside representing sub-branches. Treemaps are useful for visualizing part-to-whole relationships and comparing the size of different categories.
You can customize the colors, labels, and hierarchy to represent your data effectively.
Common Uses
- Hierarchical Data Visualization: Displaying nested data as a set of rectangles.
- Part-to-Whole Relationships: Visualizing how different categories contribute to the whole.
- Categorical Data: Showing categorical breakdowns with nested structures.
Check out the Attributes for the full set of configuration options
Unexpected Behavior
The terminal values of a treemap
must be unique. In other words- if you create a treemap with multiple parent-child trees, the values must be unique across all squares that have no children.
Examples
Common Configurations
Here's a simple treemap
plot showing a hierarchy of categories:
You can copy this code below to create this chart in your project:
models:
- name: treemap-data
args:
- echo
- |
labels,parents,values
Total,,100
A,Total,40
B,Total,30
C,Total,30
D,A,10
E,A,20
F,B,10
traces:
- name: Simple Treemap Plot
model: ${ref(treemap-data)}
props:
type: treemap
labels: ?{labels}
parents: ?{parents}
values: ?{"values"}
marker:
colorscale: Blackbody
textposition: "middle center"
texttemplate: "<b>%{label}</b>"
textfont:
size: 12
charts:
- name: Simple Treemap Chart
traces:
- ${ref(Simple Treemap Plot)}
layout:
title:
text: Simple Treemap Chart<br><sub>Hierarchical Data Visualization</sub>
This example demonstrates a treemap
plot where each category has custom colors:
Here's the code:
models:
- name: treemap-data-colors
args:
- echo
- |
labels,parents,values,colors
Total,,100,#1f77b4
A,Total,40,#ff7f0e
B,Total,30,#2ca02c
C,Total,30,#d62728
D,A,10,#9467bd
E,A,20,#8c564b
F,B,10,#e377c2
traces:
- name: Treemap Plot with Custom Colors
model: ${ref(treemap-data-colors)}
props:
type: treemap
labels: ?{labels}
parents: ?{parents}
values: ?{"values"}
marker:
colors: ?{colors}
line:
color: black
charts:
- name: Treemap Chart with Custom Colors
traces:
- ${ref(Treemap Plot with Custom Colors)}
layout:
title:
text: Treemap Plot with Custom Colors<br><sub>Custom Colors for Each Category</sub>
Here's a treemap
plot where the tiling algorithm is customized:
Here's the code:
models:
- name: treemap-data-tiling
args:
- echo
- |
labels,parents,values
Total,,100
A,Total,40
B,Total,30
C,Total,30
D,A,15
E,A,25
F,B,10
G,B,20
H,C,15
I,C,15
traces:
- name: Treemap Plot with Custom Tiling
model: ${ref(treemap-data-tiling)}
props:
type: treemap
labels: ?{labels}
parents: ?{parents}
values: ?{"values"}
tiling:
packing: binary
squarifyratio: 1.5
charts:
- name: Treemap Chart with Custom Tiling
traces:
- ${ref(Treemap Plot with Custom Tiling)}
layout:
title:
text: Treemap Plot with Custom Tiling<br><sub>Binary Packing and Custom Squarify Ratio</sub>
A schema to validate plotly trace properties
Attributes
These attributes apply to traces where trace.props.type
is set to treemap
. You would configure these attributes on the trace with the trace.props
object.
branchvalues: 'any'
count: 'string'
customdata: 'array'
customdatasrc: 'string'
domain:
column: 'integer'
row: 'integer'
x: 'array'
y: 'array'
hoverinfo: 'array'
hoverinfosrc: 'string'
hoverlabel:
align: 'array'
alignsrc: 'string'
bgcolor: 'color | array'
bgcolorsrc: 'string'
bordercolor: 'color | array'
bordercolorsrc: 'string'
font:
color: color | array
colorsrc: 'string'
family: 'string | array'
familysrc: 'string'
lineposition: 'array'
linepositionsrc: 'string'
shadow: 'string | array'
shadowsrc: 'string'
size: number | array
sizesrc: 'string'
style: 'array'
stylesrc: 'string'
textcase: 'array'
textcasesrc: 'string'
variant: 'array'
variantsrc: 'string'
weight: 'integer | array'
weightsrc: 'string'
namelength: 'integer | array'
namelengthsrc: 'string'
hovertemplate: 'string | array'
hovertemplatesrc: 'string'
hovertext: 'string | array'
hovertextsrc: 'string'
ids: 'array'
idssrc: 'string'
insidetextfont:
color: color | array
colorsrc: 'string'
family: 'string | array'
familysrc: 'string'
lineposition: 'array'
linepositionsrc: 'string'
shadow: 'string | array'
shadowsrc: 'string'
size: number | array
sizesrc: 'string'
style: 'array'
stylesrc: 'string'
textcase: 'array'
textcasesrc: 'string'
variant: 'array'
variantsrc: 'string'
weight: 'integer | array'
weightsrc: 'string'
labels: 'array'
labelssrc: 'string'
legend: 'string'
legendgrouptitle:
font:
color: any
family: 'string'
lineposition: 'string'
shadow: 'string'
size: number
style: 'any'
textcase: 'any'
variant: 'any'
weight: 'integer'
text: 'string'
legendrank: 'number'
legendwidth: 'number'
marker:
autocolorscale: 'boolean'
cauto: 'boolean'
cmax: 'number'
cmid: 'number'
cmin: 'number'
coloraxis: 'string'
colorbar:
bgcolor: 'any'
bordercolor: 'any'
borderwidth: 'number'
exponentformat: 'any'
len: 'number'
lenmode: 'any'
minexponent: 'number'
nticks: 'integer'
orientation: 'any'
outlinecolor: 'any'
outlinewidth: 'number'
separatethousands: 'boolean'
showexponent: 'any'
showticklabels: 'boolean'
showtickprefix: 'any'
showticksuffix: 'any'
thickness: 'number'
thicknessmode: 'any'
tickangle: 'number'
tickcolor: 'any'
tickfont:
color: any
family: 'string'
lineposition: 'string'
shadow: 'string'
size: number
style: 'any'
textcase: 'any'
variant: 'any'
weight: 'integer'
tickformat: 'string'
tickformatstops: array
ticklabeloverflow: 'any'
ticklabelposition: 'any'
ticklabelstep: 'integer'
ticklen: 'number'
tickmode: 'any'
tickprefix: 'string'
ticks: 'any'
ticksuffix: 'string'
ticktext: 'array'
ticktextsrc: 'string'
tickvals: 'array'
tickvalssrc: 'string'
tickwidth: 'number'
title:
font:
color: any
family: 'string'
lineposition: 'string'
shadow: 'string'
size: number
style: 'any'
textcase: 'any'
variant: 'any'
weight: 'integer'
side: 'any'
text: 'string'
x: 'number'
xanchor: 'any'
xpad: 'number'
xref: 'any'
y: 'number'
yanchor: 'any'
ypad: 'number'
yref: 'any'
colors: 'array'
colorscale: 'any'
colorssrc: 'string'
cornerradius: 'number'
depthfade: 'any'
line:
color: 'color | array'
colorsrc: 'string'
width: 'number | array'
widthsrc: 'string'
pad:
b: 'number'
l: 'number'
r: 'number'
t: 'number'
pattern:
bgcolor: 'color | array'
bgcolorsrc: 'string'
fgcolor: 'color | array'
fgcolorsrc: 'string'
fgopacity: 'number'
fillmode: 'any'
shape: 'array'
shapesrc: 'string'
size: 'number | array'
sizesrc: 'string'
solidity: 'number | array'
soliditysrc: 'string'
reversescale: 'boolean'
showscale: 'boolean'
maxdepth: 'integer'
metasrc: 'string'
name: 'string'
opacity: 'number'
outsidetextfont:
color: color | array
colorsrc: 'string'
family: 'string | array'
familysrc: 'string'
lineposition: 'array'
linepositionsrc: 'string'
shadow: 'string | array'
shadowsrc: 'string'
size: number | array
sizesrc: 'string'
style: 'array'
stylesrc: 'string'
textcase: 'array'
textcasesrc: 'string'
variant: 'array'
variantsrc: 'string'
weight: 'integer | array'
weightsrc: 'string'
parents: 'array'
parentssrc: 'string'
pathbar:
edgeshape: 'any'
side: 'any'
textfont:
color: color | array
colorsrc: 'string'
family: 'string | array'
familysrc: 'string'
lineposition: 'array'
linepositionsrc: 'string'
shadow: 'string | array'
shadowsrc: 'string'
size: number | array
sizesrc: 'string'
style: 'array'
stylesrc: 'string'
textcase: 'array'
textcasesrc: 'string'
variant: 'array'
variantsrc: 'string'
weight: 'integer | array'
weightsrc: 'string'
thickness: 'number'
visible: 'boolean'
root:
color: 'any'
sort: 'boolean'
stream:
maxpoints: 'number'
token: 'string'
text: 'array'
textfont:
color: color | array
colorsrc: 'string'
family: 'string | array'
familysrc: 'string'
lineposition: 'array'
linepositionsrc: 'string'
shadow: 'string | array'
shadowsrc: 'string'
size: number | array
sizesrc: 'string'
style: 'array'
stylesrc: 'string'
textcase: 'array'
textcasesrc: 'string'
variant: 'array'
variantsrc: 'string'
weight: 'integer | array'
weightsrc: 'string'
textinfo: 'string'
textposition: 'any'
textsrc: 'string'
texttemplate: 'string | array'
texttemplatesrc: 'string'
tiling:
flip: 'string'
packing: 'any'
pad: 'number'
squarifyratio: 'number'
type: treemap
uid: 'string'
values: 'array'
valuessrc: 'string'
visible: 'any'