Ordering y-axis of seaborn boxplot?

浪尽此生 提交于 2021-01-29 14:48:47

问题


I have the following view:

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?


回答1:


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]



来源:https://stackoverflow.com/questions/57881260/ordering-y-axis-of-seaborn-boxplot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!