Squarify

0.4.4 · active · verified Thu Apr 16

Squarify is a pure Python library that implements the squarify treemap layout algorithm. It's commonly used for data visualization, specifically to create treemaps, often in conjunction with Matplotlib. The library is currently at version 0.4.4 and appears to have an active release cadence, with the latest version released in July 2024.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a basic treemap using `squarify.plot()`. It shows how to define sizes and labels, sort the sizes (a requirement for squarify), and render the treemap using Matplotlib.

import squarify
import matplotlib.pyplot as plt

sizes = [500, 433, 78, 25, 25, 7]
labels = ['Category A', 'Category B', 'Category C', 'Category D', 'Category E', 'Category F']
colors = ['#4C72B0', '#55A868', '#C44E52', '#8172B2', '#CCB974', '#64B5CD']

# Sort sizes in descending order as required by squarify
sizes.sort(reverse=True)

plt.figure(figsize=(10, 6))
squarify.plot(sizes=sizes, label=labels, color=colors, alpha=0.8)
plt.title('Treemap Visualization with Squarify')
plt.axis('off') # Removes axes to show only the treemap
plt.show()

view raw JSON →