How to set the hue order in Seaborn plots

In order to manually select the hue order of a Seaborn plot, you have to define the desired order as a list and then pass it to the plot function as the argument hue_order . The following code would work:

import seaborn as sns

titanic = sns.load_dataset("titanic")
hue_order = ['Third', 'Second', 'First']
sns.catplot(x="sex", y="survived", hue="class", data=titanic, hue_order=hue_order, kind="bar")

Leave a Comment