I am having a problem with Facetgrid: when I use the hue parameter, the x-labels show up in the wrong order and do not match the data. Loading the Tita
If you are going to use FacetGrid
with one of the categorical plotting functions, you need to supply order information, either by declaring the variables as categorical or with the order
and hue_order
parameters:
g = sns.FacetGrid(titanic, col='pclass', hue='survived')
g = g.map(sns.swarmplot, 'sex', 'age', order=["male", "female"], hue_order=[0, 1])
However, it is generally preferable to use factorplot
, which will take care of this bookkeeping for you and also save you some typing:
g = sns.factorplot("sex", "age", "survived", col="pclass", data=titanic, kind="swarm")