Registry / data / squarify

squarify

JSON →
library0.4.4pypypi✓ verified 85d ago

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.

pip install squarify
INSTALL
IMPORT
SIG · SQUARIFY
S
squarify
datapythonv0.4.4
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.4.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

squarify
import squarify
from squarify import squarify
The common pattern is to import the entire module as 'squarify', then call functions like `squarify.plot()` or `squarify.squarify()`.
pyplot
import matplotlib.pyplot as plt
Required when using the `squarify.plot` function for visualization.

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()
Debug
Known issues
gotchaInput `sizes` list must be positive values and sorted in descending order before passing to `squarify.squarify` or `squarify.plot`.
fix
Always sort your `sizes` list: `sizes.sort(reverse=True)`.
affects: All versions
gotchaFor `squarify.squarify` (the layout function), the sum of `sizes` should equal the total area (`dx * dy`). Use `squarify.normalize_sizes(values, dx, dy)` to prepare your values if they don't already match the target area.
fix
Use `normalized_sizes = squarify.normalize_sizes(original_sizes, width, height)` before calling `squarify.squarify(normalized_sizes, ...)`.
affects: All versions
gotchaThe `squarify` algorithm prioritizes aspect ratios close to 1. This can sometimes lead to less clarity in hierarchical structures or instability in layout with small data changes compared to other treemap algorithms.
fix
Be aware of this characteristic; for applications requiring strict hierarchy visibility or layout stability for animations, consider alternative treemap implementations.
affects: All versions
Errors
Common errors & fixes
AttributeError: module 'squarify' has no attribute 'plot'
This typically occurs if a local file named `squarify.py` exists in your working directory, shadowing the installed `squarify` library. Another cause can be not importing `matplotlib.pyplot` if `squarify.plot` is being used.
fix
Rename any local file named `squarify.py` or ensure `import matplotlib.pyplot as plt` is present if you intend to use `squarify.plot`.
ModuleNotFoundError: No module named 'squarify'
The `squarify` package is not installed in the Python environment you are currently using, or there's a mismatch between where it's installed and where your interpreter is looking.
fix
Install the package using `pip install squarify`. If using a virtual environment or Jupyter/IDE, ensure the correct Python interpreter path is selected.
Labels for small treemap squares overlap or go out of bounds, making them unreadable.
By default, `squarify.plot` may not automatically adjust label font sizes or positions for very small rectangles, leading to visual clutter.
fix
Manually adjust font size using `text_kwargs={'fontsize': N}` or consider adding custom logic for label placement/wrapping for smaller squares. For highly dynamic or dense treemaps, some labels may need to be omitted.
Upgrade
Version history
0.4.4latest on PyPI · released Jul 19, 2024
Audit
Dependencies
matplotliboptionalRequired for the `squarify.plot` helper function to render treemaps.
Agent activity
15 hits · last 30 days
node
10
OpenAI (training)
1
Resources
squarify — pip install squarify · libregistry