Hue parameter in seaborn FacetGrid

后端 未结 1 651
深忆病人
深忆病人 2021-02-06 05:25

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

相关标签:
1条回答
  • 2021-02-06 06:04

    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")
    

    0 讨论(0)
提交回复
热议问题