0

I would like to order the bars in my seaborn plot using the y axis, so in this case the 'Fraud Probability' in descending order. How can I do that? This is my code:

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()

And this is the resulting plot: enter image description here

Sheldore
  • 37,862
  • 7
  • 57
  • 71
Marco
  • 1,195
  • 3
  • 18
  • 30
  • 1
    Just sort your data frame using `Fraud Probability`, save it in a new dataframe and plot it. [Here](https://stackoverflow.com/questions/46072509/pandas-dataframe-sort-by-a-column) is a link on how to sort the data frame. Use `ascending=False` to have the values sorted in descending order. Simple! – Sheldore Sep 13 '18 at 17:09

1 Answers1

2

The dataset was already sorted. Anyway after sorting the dataset, in this case the name is fraud_df, you just need to specify order = fraud_df['Customer ID'] like this:

ax = sns.barplot(x = 'Customer ID', y = "Fraud Probability", data = fraud_df, order = fraud_df['Customer ID']) 
Sheldore
  • 37,862
  • 7
  • 57
  • 71
Marco
  • 1,195
  • 3
  • 18
  • 30