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
Parameters | Type | Default | Description |
---|---|---|---|
table | Table | DataFrame | A table to pull data from. | |
names | str | None | None | The column containing names of the sections |
values | str | None | None | The column containing values of the sections |
parents | str | None | None | The column containing parents of the sections |
ids | str | None | None | The column containing ids of the sections. Unlike values, these must be unique. Values are used for ids if ids are not specified. |
color | str | list[str] | None | None | A 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_name | str | None | None | A column that contains names to bold in the hover tooltip. |
labels | dict[str, str] | None | None | A dictionary of labels mapping columns to new labels. |
color_discrete_sequence | list[str] | None | None | A 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_map | dict[str | tuple[str], str] | None | None | If dict, the keys should be strings of the column values (or a tuple of combinations of column values) which map to colors. |
color_continuous_scale | list[str] | None | None | A list of colors for a continuous scale |
range_color | list[float] | None | None | A list of two numbers that form the endpoints of the color axis |
color_continuous_midpoint | float | None | None | A number that is the midpoint of the color axis |
title | str | None | None | The title of the chart |
template | str | None | None | The template for the chart. |
branchvalues | str | None | None | Set 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. |
maxdepth | int | None | None | Sets the total number of visible levels. Set to -1 to render all levels. |
unsafe_update_figure | Callable | <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. |