【发布时间】:2020-01-05 08:17:46
【问题描述】:
我有一个 seaborn 计数图,其中包含了“色调参数”,这就是绘图的样子:
男
男性总人数 = 240 669,活跃男性总人数 = 130 856,流失男性总人数 = 109 813
M(活跃)--- 130856/240669 = 54.4% 和 M(流失)--- 109813/240669 =45.6%
女性
女性总人数 = 198 408,活跃女性总人数 = 111 107,流失女性总人数 = 87 301
所以 F(活跃)--- 111107/198408 = 56% 和 F(流失)--- 87301/198408 =44%
我希望每个性别的总百分比为 100%,而不是附图中给出的百分比。
这是我使用的代码:
plt.figure(figsize=(10,6))
colours = ['b','red']
ax = sns.countplot(df.GENDER,hue=df['Status'],order =
df['GENDER'].value_counts().index,palette=colours)
plt.title("GENDER VS STATUS",fontsize=15)
plt.tight_layout()
plt.xticks(fontsize=14)
plt.yticks(fontsize=14)
total = float(len(df))
for p in ax.patches:
height = p.get_height()
ax.text(p.get_x()+p.get_width()/2.,
height + 3,
'{0:.1%}'.format(height/total),
ha="center", fontsize=15)
print(df['GENDER'].value_counts(normalize=True))
【问题讨论】:
标签: python-3.x matplotlib seaborn