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
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibcpy 3.10–3.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()
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.
fixRename 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.
fixInstall 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.
fixManually 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.