I can't find a way in Squarify's documentation to edit the shapes of the rectangles inside the treeplot. I want to show one of the rectangles as a square subset of one of the other rectangles. This is what I have currently:
import squarify
from matplotlib import pyplot as plt
treemap_df = pd.DataFrame({
'names': ['A', 'B', 'C'],
'sizes': [25, 50, 75]
})
plt.figure(figsize=(10, 4))
ax = squarify.plot(
treemap_df.sizes,
label=treemap_df.names,
color=["red","green","grey"],
alpha=.8,
edgecolor="white",
linewidth=4
)
# I can get the coordinates of the squares/patches like this:
for rect in ax.patches:
x, y, w, h = rect.get_x(), rect.get_y(), rect.get_width(), rect.get_height()
c = rect.get_facecolor()
print(f'Rectangle x={rect.get_x()} y={rect.get_y()} w={rect.get_width()} h={rect.get_height()} ')
plt.axis('off')
plt.title('Basic Treemap')
plt.show()
This gives me the following output:
So, let's say that I just want to edit the plot so that rectangle 'A' is a square — is there a way I can do that? Ideally I'd like to be able to have shape 'B' not even be a square but to look like 'A' is an inset into rectangle 'B' (which would then have an L shape in its actual footprint), but just being able to tweak the rectange shape/locations at all would be great. Thanks.