标签: squarify

Squarify - 自动调整树状图中标签的大小

我正在使用Squarify在 Python 中实现一个简单的树形图。

我正在绘制艺术家姓名及其在所考虑的歌曲图表中的流百分比,正方形越大/越暗,值越高。

我的代码如下:

dataGoals = sort_by_streams[sort_by_streams["Streams"]>1]

#Utilise matplotlib to scale our stream number between the min and max, then assign this scale to our values.
norm = matplotlib.colors.Normalize(vmin=min(dataGoals.Streams), vmax=max(dataGoals.Streams))
colors = [matplotlib.cm.Blues(norm(value)) for value in dataGoals.Streams]

#Create our plot and resize it.
fig1 = plt.figure()
ax = fig1.add_subplot()
fig1.set_size_inches(16, 4.5)

#Use squarify to plot our data, label it and add colours. We add an alpha layer to ensure black labels show through
labels = ["%s\n%.2f" % …
Run Code Online (Sandbox Code Playgroud)

python matplotlib treemap squarify

7
推荐指数
1
解决办法
2780
查看次数

如何在树状图上添加 % 信息?

我正在绘制树形图,想知道如何绘制树类的相对百分比,即

A 组 =100
组 B =30
组 C =50
组 D =20

然后,在图中,它应该 在其“X 组”标签旁边添加:“
50%”用于 A 组,“
15%”用于 B 组
等。鉴于此代码,我将如何做到这一点?

!pip install squarify
import squarify 
df = pd.DataFrame({'customers':[8,3,4,2], 'cluster':["group A", "group B", "group C", "group D"] })
squarify.plot(sizes=df['customers'], label=df['cluster'], alpha=.8 )
plt.axis('off')
plt.show();
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

python python-3.x squarify

5
推荐指数
1
解决办法
1688
查看次数

使用 squareify.plot 在标签上显示多列值

我有一个数据框,我想用它来绘制树图squarify。我想通过编辑参数在图表上显示country_name和,但它似乎只采用一个值。countslabels

示例数据

import squarify
import pandas as pd
from matplotlib import pyplot as plt
d = {'country_name':['USA', 'UK', 'Germany'], 'counts':[100, 200, 300]}
dd = pd.DataFrame(data=d)
Run Code Online (Sandbox Code Playgroud)
fig = plt.gcf()
ax = fig.add_subplot()
fig.set_size_inches(16, 4.5)
norm = matplotlib.colors.Normalize(vmin=min(dd.counts), vmax=max(dd.counts))
colors = [matplotlib.cm.Blues(norm(value)) for value in dd.counts]
squarify.plot(label=dd.country_name, sizes=dd.counts, alpha=.7, color=colors)
plt.axis('off')
plt.show()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

预期输出将在图表上同时出现counts和。country_name

matplotlib pandas squarify

1
推荐指数
1
解决办法
855
查看次数

标签 统计

squarify ×3

matplotlib ×2

python ×2

pandas ×1

python-3.x ×1

treemap ×1