如何更改seaborn中因子图的顺序

如何更改seaborn中因子图的顺序

本文介绍了如何更改seaborn中因子图的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据如下:

m=pd.DataFrame({'model':['1','1','2','2','13','13'],'rate':randn(6)},index=['0', '0','1','1','2','2'])

我想使因子图的x轴顺序为[1,2,13],但默认值为[1,13,2].

I want to have the x-axis of factor plot ordered in [1,2,13] but the default is [1,13,2].

有人知道如何更改吗?

更新: 我想我已经通过以下方式解决了这个问题,但是也许有更好的方法通过使用索引来做到这一点?

Update: I think I have figured it out in the following way, but maybe there is a better way by using an index to do that?

sns.factorplot('model','rate',data=m,kind="bar",x_order=['1','2','13'])

推荐答案

您对帖子的更新显示了执行此操作的正确方法,即您应按所需顺序将x值列表传递给order他们密谋了.数字数据的默认设置是按排序顺序进行绘制,因此,如果您有数字值,则最好将它们保留为整数或浮点数而不是字符串,这样它们将采用自然"顺序.

Your update to the post shows the correct way to do it, i.e. you should pass a list of x values to order in the order you want them plotted. The default for numeric data is to plot in sorted order, so if you have numeric values it's best to keep them as integers or floats instead of strings, so they will be in "natural" order.

这篇关于如何更改seaborn中因子图的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 05:15