如何在Python

问题描述 投票:0回答:1

I发现了这个情节/图,我想在Python中重新创建它。感觉就像是带有固定标签之类的热图,但我认为应该有一个更好的解决方案。任何帮助或提示将不胜感激。 在理想情况下,该解决方案将用于matplotlib/seaborn。 The diagram

python matplotlib plot seaborn diagram
1个回答
0
投票

这里是重新创建图像的Python代码:

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()
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.