Repository navigation
UltraPlot 2.7.6 adds ax.treemap(). Pass a dictionary of category sizes to draw a tile for each category. Nest the dictionaries to split each group into smaller tiles.
In this illustrative plan, 26 hectares of pasture become 16 hectares of marsh and 10 hectares of meadow. Each habitat keeps its color across the two panels.
Plotting code
import ultraplot as uplt
# An illustrative restoration plan for a 100-hectare reserve.
before = {
"Woodland": {"Oak": 26, "Birch": 14},
"Grassland": {"Pasture": 38, "Meadow": 12},
"Wetland": {"Marsh": 10},
}
after = {
"Woodland": {"Oak": 26, "Birch": 14},
"Grassland": {"Pasture": 12, "Meadow": 22},
"Wetland": {"Marsh": 26},
}
palette = ["#176b59", "#dcb45e", "#3c7798"]
fig, axs = uplt.subplots(ncols=2, refwidth=3.6, refaspect=1, share=False)
for ax, habitats in zip(axs, (before, after)):
ax.treemap(
habitats, cycle=palette, show_values=True, value_format="{:.0f} ha",
group_pad=0.022, pad=0.008, text_kw={"size": 11},
)
axs.format(
suptitle="Restoring a 100-hectare reserve",
toplabels=["Current habitat", "Restoration plan"],
)
fig.show()To color tiles by size, pass cmap="viridis". You can use the returned artists["mappable"] with ax.colorbar(). The returned patches, text, and values follow the input order.
What's changed
- Add treemaps (#854).
Full changelog from v2.7.5 to v2.7.6
What's Changed
- Add treemaps by @cvanelteren in #854
Full Changelog: v2.7.5...v2.7.6