【问题标题】:Unable to display the percentage on the barplot无法在条形图上显示百分比
【发布时间】:2020-12-04 04:24:52
【问题描述】:

我在下面构建了一个代码来显示条形图顶部的百分比。但是在运行代码时,百分比不显示。

谁能帮我在条形图的顶部获得百分比。

【问题讨论】:

    标签: pandas bar-chart data-science seaborn


    【解决方案1】:

    你可以试试这个。

    for p in b.patches:
        height = p.get_height()
        b.text(p.get_x()+p.get_width()/2.,
                height + 3,
                '{:1.2f}'.format(height/len(df)),
                ha="center")
    

    【讨论】:

    • 嗨,Arpit,它运作良好。但是我怎么能做到这一点。
    • 只需将您的色调提供为sns.countplot(hue='coolwarm')
    猜你喜欢
    • 2019-02-04
    • 2017-09-15
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 2022-12-01
    • 2023-04-02
    • 2020-02-29
    • 1970-01-01
    相关资源
    最近更新 更多