I found this plot/diagram and I would like to recreate it in Python. It feels like a heatmap with fixed labels or something, but I think there should be a better solution than that. Any help or hints would be appreciated.
In ideal case the solution will be in matplotlib/seaborn.

-
1What is your input data? Please provide a minimal reproducible example of the input data as code (ideally that would match exactly the example plot shown here).mozway– mozway2025-03-14 12:44:56 +00:00Commented Mar 14 at 12:44
-
There is little bit difference in box colors. It will take time for me to set the colors. Could you edit the code for box colors?Subir Chowdhury– Subir Chowdhury2025-03-14 12:54:20 +00:00Commented Mar 14 at 12:54
-
Here is the image I created using matplotlib drive.google.com/file/d/1K1L_wWBSS0i8knjEcKzkF2x1YPCeEj7j/… . It requires some editing for colors. Could you please accept it?Subir Chowdhury– Subir Chowdhury2025-03-14 12:58:31 +00:00Commented Mar 14 at 12:58
-
1see e.g. Squarify - Auto resize label in treemap or [stackoverflow.com/questions/65465548/… In Python - Vertical and Horizontal). Note that on StackOverflow you are supposed to provide reproducible test data and your best-effort code attempt.JohanC– JohanC2025-03-14 13:10:38 +00:00Commented Mar 14 at 13:10
-
@mozway the thing is I do not have any data. the question is about recreating the image provided. To be more specific. Im interested in creating such full blocks with distinct colors and a labelkohoutek– kohoutek2025-03-14 13:41:11 +00:00Commented Mar 14 at 13:41
|
Show 3 more comments
1 Answer
Here is python code to recreate the image:
import matplotlib.pyplot as plt
import squarify #pip install squarify
labels = [
"can't loose them", "loyal customers", "champions", "at risk", "need attention",
"potential loyalists", "new customers", "promising", "about to sleep", "hibernating"
]
sizes = [20, 25, 15, 20, 10, 25, 5, 10, 10, 15] # Adjusted sizes to match the number of labels
# Define colors to match the provided image
colors = ["#ff6666", "#66b3ff", "#33cc99", "#ffa500", "#ffff66",
"#9370DB", "#90EE90", "#20B2AA", "#8B4513", "#A9A9A9"]
plt.figure(figsize=(10, 6))
squarify.plot(sizes=sizes, label=labels, color=colors, alpha=0.7, text_kwargs={'fontsize': 10})
plt.xlabel("R", fontsize=12, fontweight='bold')
plt.ylabel("F", fontsize=12, fontweight='bold')
plt.axis("off")
plt.show()
Output:
