Treemap Plot

Treemap plots are a data visualization technique used to represent hierarchical data in a space-filling manner. They display data as nested rectangles or squares, where the size and color of each rectangle represent the values or categories within the hierarchy. Developers can create treemaps to provide users with an efficient and visually intuitive way to explore hierarchical data structures and understand relationships between categories and subcategories, making them a valuable tool for various applications that involve hierarchical data presentation, analysis, and exploration.

Treemap plots are appropriate when the data have a hierarchical structure. Each level of the hierarchy consists of a categorical variable and an associated numeric variable with a value for each unique category.

What are treemap plots useful for?

  • Visualizing hierarchical data: Treemap plots are valuable for visualizing hierarchical data structures with multiple levels of nested categories or relationships. Developers can use treemaps to represent data in a space-efficient manner, making them suitable for applications where data has complex hierarchical organizations.
  • Hierarchical data comparison: Treemaps can be used to compare data within hierarchical structures, allowing users to understand the distribution of categories and their relative sizes. Developers can implement features that enable users to compare data across multiple hierarchies or time periods.
  • Data summarization: Treemaps are effective for summarizing large amounts of hierarchical data into a compact, visual format. Developers can use treemaps to provide users with an overview of hierarchical data, and users can drill down into specific categories for more detailed information.

Examples

A basic treemap plot

Visualize a hierarchical dataset as nested rectangles, with the size of each rectangle corresponding to a value for a particular group. Use the names argument to specify the column name for each group’s labels, the values argument to specify the column name for each group’s values, and the parents column to specify the root category of the chart.

import deephaven.plot.express as dx
gapminder = dx.data.gapminder()

# create table of only the most recent year of data, compute total population for each continent
gapminder_recent = (
    gapminder
    .last_by("Country")
    .view(["Continent", "Pop"])
    .sum_by("Continent")
    .update("World = `World`")
)

treemap_plot = dx.treemap(gapminder_recent, names="Continent", values="Pop", parents="World")

API Reference

Returns a treemap chart

Returns: DeephavenFigure A DeephavenFigure that contains the treemap chart

ParametersTypeDefaultDescription
tableTable |
DataFrame
A table to pull data from.
namesstr |
None
NoneThe column containing names of the sections
valuesstr |
None
NoneThe column containing values of the sections
parentsstr |
None
NoneThe column containing parents of the sections
idsstr |
None
NoneThe column containing ids of the sections. Unlike values, these must be unique. Values are used for ids if ids are not specified.
colorstr |
list[str] |
None
NoneA column or list of columns that contain color values. If only one column is passed, and it contains numeric values, the value is used as a value on a continuous color scale. Otherwise, the value is used for a plot by on color. See color_discrete_map for additional behaviors.
hover_namestr |
None
NoneA column that contains names to bold in the hover tooltip.
labelsdict[str, str] |
None
NoneA dictionary of labels mapping columns to new labels.
color_discrete_sequencelist[str] |
None
NoneA list of colors to sequentially apply to the series. The colors loop, so if there are more series than colors, colors will be reused.
color_discrete_mapdict[str | tuple[str], str] |
None
NoneIf dict, the keys should be strings of the column values (or a tuple of combinations of column values) which map to colors.
color_continuous_scalelist[str] |
None
NoneA list of colors for a continuous scale
range_colorlist[float] |
None
NoneA list of two numbers that form the endpoints of the color axis
color_continuous_midpointfloat |
None
NoneA number that is the midpoint of the color axis
titlestr |
None
NoneThe title of the chart
templatestr |
None
NoneThe template for the chart.
branchvaluesstr |
None
NoneSet to 'total' to take the value at a level to include all descendants and 'remainder' to the value as the remainder after subtracting leaf values.
maxdepthint |
None
NoneSets the total number of visible levels. Set to -1 to render all levels.
unsafe_update_figureCallable<function default_callback>An update function that takes a plotly figure as an argument and optionally returns a plotly figure. If a figure is not returned, the plotly figure passed will be assumed to be the return value. Used to add any custom changes to the underlying plotly figure. Note that the existing data traces should not be removed. This may lead to unexpected behavior if traces are modified in a way that break data mappings.