Skip to content

Add treemaps - #854

Open
cvanelteren wants to merge 8 commits into
mainfrom
feat/treemap
Open

cvanelteren wants to merge 8 commits into
mainfrom
feat/treemap

Conversation

@cvanelteren

Copy link
Copy Markdown
Collaborator

Closes #458 by adding ax.treemap() for flat and nested dictionaries, pandas Series, and DataFrame columns via data=df. No additional dependencies are required.

Tile areas represent values. Nested dictionaries create labeled groups with related colors. Explicit colors, colormaps, colorbars, value labels, and artist styling are supported.

# Flat categories
ax.treemap({"Solar": 36, "Wind": 28, "Hydro": 18}, show_values=True)

# Nested groups
ax.treemap({
    "Research": {"Fieldwork": 24, "Equipment": 16},
    "People": {"Staff": 20, "Training": 10},
})

# DataFrame columns
artists = ax.treemap("budget", labels="category", data=df, cmap="viridis")
ax.colorbar(artists["mappable"], label="Budget")

@codecov

codecov Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.02632% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
ultraplot/axes/plot_types/treemap.py 95.60% 5 Missing and 4 partials ⚠️

📢 Thoughts on this report? Let us know!

@cvanelteren
cvanelteren marked this pull request as draft November 3, 2026 04:15
@cvanelteren
cvanelteren marked this pull request as ready for review November 3, 2026 05:02
@cvanelteren
cvanelteren requested a review from gepcel November 5, 2026 00:14
@gepcel

gepcel commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

I'm afraid I won't have any extra time over the next three days. If you're in a hurry, feel free to merge. If anything comes up later, we can open an issue.

@cvanelteren

Copy link
Copy Markdown
Collaborator Author

@gepcel there is no rush; I can leave this open.

Comment thread ultraplot/axes/plot_types/treemap.py Resolved
Comment thread ultraplot/axes/plot_types/treemap.py Resolved
Comment thread ultraplot/axes/plot_types/treemap.py Resolved
Comment thread ultraplot/axes/plot.py
def treemap(
self,
sizes: "TreemapInput",
labels: Sequence[Any] | str | None = None,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an example that labels is a str?

@cvanelteren cvanelteren Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was intended to be the column, or entry selected from data like this

data = {"amount": [2, 3, 4], "name": ["A", "B", "C"]}
ax.treemap("amount", labels="name", data=data

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but I agree that it may be a bit confusing. It is currently also overloaded and used differently across plot and raincloud.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to think about this, we may need to align the other in raincloud too such that it is more consistent, what do you think?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with what it is now, better if there's a explanation, or examp;le. And yes, it'll be better if data, styles are handled in a consistent way.

@gepcel gepcel left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some comments. Mostly about colors. I tried some codes snippets for example:

# %%
fig,ax=pplt.subplot()
ax.treemap({"a":2,"b":3}, colors=['r', 'g'])
# %%
fig,ax=pplt.subplot()
ax.treemap({"GroupA":{"a":2,"b":3},"GroupB":{"c":4,"d":5}}, colors = ["#3c8d87", "#5286b0", "#69a4b7", "#af8a55"])
# %%
fig,ax=pplt.subplot()
ax.treemap({"GroupA":{"a":2,"b":3},"GroupB":{"c":4,"d":5}}, colors = ["#3c8d87", "#5286b0"])

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: Add Treemap

2 participants