【问题标题】:How to show percentage instead of count on my Seaborn displot y axis?如何在我的 Seaborn displot y 轴上显示百分比而不是计数?
【发布时间】:2021-04-30 19:45:06
【问题描述】:

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

【问题讨论】:

  • 简单的方法是将数据除以最大值/100。
  • 请从intro tour 重复on topichow to ask。您似乎在请人教您如何计算百分比。这是一个简单的查找,而不是一个 SO 问题。
  • @Prune Tnx 为您投反对票。但是,我不是在寻找“手动”计算百分比。我要求一种参数化的方式,我找到了。 Displot 采用 kind='hist' 作为默认值,如果将 histplot 中名为 stat 的参数设置为 stat='probability',则 y 轴显示百分比而不是计数。
  • 优秀——甚至认为实际需求不在我预期的地方。尽管如此,这仍然是简单的研究——在您在这里发布之前进行。

标签: python seaborn histogram


【解决方案1】:

sns.Displotkind='hist' 作为默认值,如果将来自sns.histplot 的参数称为stat 设置为stat='probability',则y 轴显示百分比而不是计数。所以答案是:

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

【讨论】:

    猜你喜欢
    • 2021-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-21
    • 1970-01-01
    • 2020-12-02
    • 2018-11-04
    • 1970-01-01
    相关资源
    最近更新 更多