squarify_images
squarify_images
Plot images in treemaps
Functions
| Name | Description |
|---|---|
| letterbox_extent | Compute an extent for imshow that preserves the image’s aspect ratio |
| squarify_images | Add images to fit within rectangles in a plot. |
| figtreemap | Plot treemap with figures in it. |
letterbox_extent
squarify_images.letterbox_extent(extent, img)Compute an extent for imshow that preserves the image’s aspect ratio while fitting entirely inside the given rectangle.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| extent | tuple[float, float, float, float] | A tuple (xmin, xmax, ymin, ymax) defining the rectangle bounds in data coordinates. | required |
| img | array - like | Image array shaped (H, W, C). | required |
Returns
| Name | Type | Description |
|---|---|---|
| list | A list [xmin2, xmax2, ymin2, ymax2] representing the adjusted | |
| extent that preserves the aspect ratio. |
squarify_images
squarify_images.squarify_images(
squares,
images,
ax,
letterbox=True,
aspect='auto',
)Add images to fit within rectangles in a plot. squares and images should be iterables of the same length. Optionally preserve the image aspect ratio with letterbox=True.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| squares | list[matplotlib.pathces.Rectangle] | List of rectangle objects in a plot. | required |
| images | list[PIL.PngImagePlugin.PngImageFile] | List of PNG images. | required |
| ax | matplotlib.axes._axes.Axes | A matplotlib axes to add the images to. | required |
| letterbox | bool | Should the image aspect ratio be preserved? Defaults to True. | True |
| aspect | str | aspect argument passed to imshow. Defaults to “auto”. |
'auto' |
figtreemap
squarify_images.figtreemap(
sizes,
images,
letterbox=True,
aspect='auto',
sort=True,
**kwargs,
)Plot treemap with figures in it.
Uses squarify.plot() to create a tree map then adds images to the rectangles with squarify_images. sizes and images must be in the same order so the first size goes with the first image etc.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| sizes | list[float] | An iterable of numbers to convert to colours. | required |
| images | list[PIL.PngImagePlugin.PngImageFile] | List of PNG images. | required |
| letterbox | bool | Should the image aspect ratio be preserved? Defaults to True. | True |
| sort | bool | Should the images (and other attributes) be sorted by sizes? Improves squareness. Defaults to True. | True |
| aspect | str | aspect argument passed to imshow. Defaults to “auto”. |
'auto' |
| **kwargs | Any additional keyword arguments are passed to squarify.plot e.g. facecolor and edgecolor. can be used to edit the rectangles behind the figures. Or labels can be added with label. |
{} |