【问题标题】:Seaborn barplot with bars ordered by y axisSeaborn 条形图,条形按 y 轴排序
【发布时间】:2019-02-18 11:16:14
【问题描述】:

我想使用 y 轴对我的 seaborn 图中的条形进行排序,因此在本例中,'Fraud Probability' 以降序排列。我怎样才能做到这一点? 这是我的代码:

plt.figure(figsize = (16,5))
ax = sns.barplot(x = 'Customer ID', y = "Fraud Probability", data = fraud_df)
for item in ax.get_xticklabels(): item.set_rotation(90)
plt.show()

这是结果图:

【问题讨论】:

  • 只需使用Fraud Probability 对您的数据框进行排序,将其保存在一个新的数据框中并绘制它。 Here 是关于如何对数据框进行排序的链接。使用ascending=False 使值按降序排序。简单!

标签: python matplotlib plot bar-chart seaborn


【解决方案1】:

数据集已经排序。无论如何,在对数据集进行排序后,在这种情况下名称为fraud_df,您只需指定order = fraud_df['Customer ID'],如下所示:

ax = sns.barplot(x = 'Customer ID', y = "Fraud Probability", data = fraud_df, order = fraud_df['Customer ID']) 

【讨论】:

    猜你喜欢
    • 2017-10-01
    • 2019-07-23
    • 2019-01-23
    • 2015-01-17
    • 2017-11-11
    • 2020-02-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多