-3

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. The diagram

8
  • 1
    What 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). Commented 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? Commented 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? Commented Mar 14 at 12:58
  • 1
    see 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. Commented 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 label Commented Mar 14 at 13:41

1 Answer 1

2

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:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.