AI52487963
AI52487963

Reputation: 1273

Ordering y-axis of seaborn boxplot?

I have the following view: enter image description here

but I'd like to have the y-axis here ordered so the num_engagements field is increasing as the y-axis goes up instead of the reverse case here. I've tried playing with the order field in the seaborn options, but if I set order=['num_engagements'] then I just get a blank plot as a result.

Any thoughts?

Upvotes: 0

Views: 1220

Answers (1)

Toukenize
Toukenize

Reputation: 1420

You need to pass in a list of all the y-axis labels to your order keyword. The following would achieve what you want:

sns.boxplot(y='num_engagements', x='channel_spend1', showfliers=False, 
            orient='h', data=rep_data_imputed, order=['13','12','11','10','9'])

One thing to note, currently your number of engagement is being treated as a categorical variable, thus I specified the order as ['13','12','11','10','9'], with single quotation marks. If it doesn't work, try [13,12,11,10,9]

Upvotes: 1

Related Questions