首页 > 解决方案 > 如何在我的 Seaborn displot y 轴上显示百分比而不是计数?

问题描述

我有以下代码:
sns.displot(data_df_cleaned, x='estimate_error', bins = [-30, -5, 5, 30, 80])
它绘制了以下简单的直方图,但我希望我的y 轴报告百分比。使用 Seaborn 执行此操作很重要,对此我在文档或 stackoverflow 中找不到任何答案。

在此处输入图像描述

标签: pythonseabornhistogram

解决方案


sns.Displot采用kind='hist'默认值,如果sns.histplot调用的参数stat设置为stat='probability',则 y 轴显示百分比而不是计数。所以答案是:

sns.displot(data_df_cleaned, x='estimate_error', bins = [-30, -5, 5, 30, 80], stat='probability')

推荐阅读