Search code examples
pythonseabornfacet-grid

ValueError: `multiple` must be one of ['layer', 'stack', 'fill', 'dodge'], but s was passed.`


I am trying to stack my histplot FaceGrid plot with "multiple" in "hue_kws"

fg1 = sns.FacetGrid(data=df, col="type", col_wrap=3, hue="class", height=3.5,
                    hue_kws={"multiple": 'stack'}
                    )
fg1.map_dataframe(sns.histplot, x="col_name")

I get the error in the title. If I pass

hue_kws={"multiple": 'layer'}

the error changed to

ValueError: `multiple` must be one of ['layer', 'stack', 'fill', 'dodge'], but l was passed.`

So I guess only the first letter of the string of the value is passed. What am I missing?


Solution

  • You're using hue_kws incorrectly. Its parameter type documentation has "dictionary of param -> list of values mapping". So it is trying to use the first letter of your string for the first hue level, the second letter of your string for the second hue variable, etc. This is not what you want.

    While you can use FacetGrid directly, it's simpler, and safer, to use displot:

    fg1 = sns.displot(df, x="col_name", hue="class",
                      col="type", col_wrap=3,
                      height=3.5, multiple="stack")