0
votes

I wan to plot a seaborn catplot with multiple columns and using the hue to differentiate some observations.

Lets say I have

import pandas as pd
import seaborn as sns
import random as r
import numpy as np

name_list=['pepe','Fabrice','jim','Michael']
country_list=['spain','France','uk','Uruguay']
favourite_color=['green','blue','red','white']

df=pd.DataFrame({'name':[r.choice(name_list) for n in range(100)],
         'country':[r.choice(country_list) for n in range(100)],
         'fav_color':[r.choice(favourite_color) for n in range(100)],
         'score':np.random.rand(100),})

If I run

sns.catplot(y='score',hue='fav_color',col='country',data=df)

I get a TypeError: 'NoneType' object is not iterable. If I specify legend=False, I do not get any error but all points seem of the same color. I tried also to specify the palette with the same result. Is this a bug or am I doing something wrong?

1
I think you forgot to specify what to show on the xaxis. In this case maybe the names? sns.catplot(x="name", y='score',hue='fav_color',col='country',data=df)ImportanceOfBeingErnest
I see... I didn't specify x because I wanted one per column... what I am plotting has different units and I wanted to use sharey=False. Maybe it is better to do 4 different stripplots with FacetGridNabla

1 Answers

0
votes

You can try giving X as hue value with different options in kind like point or strip etc.

    sns.catplot(y='score', x='fav_color',col='country',data=df, kind='point')
    sns.catplot(y='score', x='fav_color',col='country',data=df)

OR

specify kind = 'count' without X variable like this

    sns.catplot(y='score',hue='fav_color',col='country',data=df,kind='count')