how to change the order of factor plot in seaborn how to change the order of factor plot in seaborn pandas pandas

how to change the order of factor plot in seaborn


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.


As @Pablo wrote in his comment and @Archie correctly mentioned in their answer:

x_order should be replaced by order

For those who came here looking for a sort solution for kind="count", it is possible to do so:

sns.catplot(x="model", data=m, kind="count", order=m.model.value_counts().index)

It's because by default value_counts method will return descending sorted values by count.


From the documentation it appears that the seaborn API has updated again, the argument x_order should be replaced by order:

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

Also, factorplot has been renamed and will be removed in future releases; it is replaced by catplot:

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