0

I have three datasets, and I am now making 3 different box plots. Right now I am using:

chart1 = sns.catplot(x="Provider", y="Appearances", kind="box", data=mlt_sample1k)
chart2 = sns.catplot(x="Provider", y="Appearances", kind="box", data=mlt_sample10k)
chart3 = sns.catplot(x="Provider", y="Appearances", kind="box", data=mlt_sample100k)

where mlt_sample1k, mlt_sample10k and mlt_sample100k are my three dataframes.

I want to combine these into a single boxplot, with 3 parallel boxes per provider, as in the example from the docs. Something like:

enter image description here

but with 3 boxes, and the Thu, Fri, etc would be my "provider" categories. I see that in the docs they simply use:

ax = sns.boxplot(x="day", y="total_bill", hue="smoker",

                 data=tips, palette="Set3")

However this does not work for me, as I have to specify three datasets, one for each box. How can I do this?

EDIT: The structure of my dataframes is always the same:

item  |  provider  | appearances

'dog'    'prov1'      0.001
'cat'    'prov2'      0.02
'pig'    'prov1'      0.03
...

The box plots represent the statistics of the items, according to the appearances column, per each provider (6 in total) per each dataframe.

The three dataframes are NOT the same length.

2
  • More information on the dfs structure would be useful. Have you tried creating an axis object and passing this to each individual call of boxplot? Commented May 29, 2020 at 6:32
  • @FChm I have edited my answer with the dataframe structures. As for your suggestion, I am not sure what you mean. Could you try and paste a small code example? Commented May 29, 2020 at 6:36

1 Answer 1

1

IIUC, you could concat the three dataframes and assign a column to be used as the hue like:

sns.catplot(x="Provider", y="Appearances", 
            kind="box", hue='h',
            data=pd.concat([mlt_sample1k.assign(h='1k'), 
                            mlt_sample10k.assign(h='10k'), 
                            mlt_sample100k.assign(h='100k')])
           )
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.