unable to create diagonal histogram in seaborn

Viewed 326

I'm trying to create a diagonal histogram using pairplot() in seaborn, below is my code:

import seaborn as sb

colors = ['#c994c7','#dd1c77','#c51b8a','#fa9fb5','#9ebcda','#feb24c']

ds = sb.load_dataset('titanic')
sb.pairplot(ds,hue='embark_town',palette=colors,kind='scatter',diag_kind='hist')

But I'm getting the following error:

TypeError: NumPy boolean subtract, the `-` operator, is deprecated, use the bitwise_xor, the `^` operator, or the logical_xor function instead.

Although it creates histogram diagonally but it doesn't create any non entity-relationship plots using the kind parameter. the above code works fine when I use 'kde' in diag_kind parameter.

1 Answers

Okay, I noticed that the problem is happening due to the boolean dtype of the 'adult_male' and 'alone' column, a work-around is to change the dtype of those columns.

colors = ['#c994c7','#dd1c77','#c51b8a','#fa9fb5','#9ebcda','#feb24c']

ds = sns.load_dataset('titanic')
ds['adult_male'] = ds['adult_male'].astype(str)
ds['alone'] = ds['alone'].astype(str)
sns.pairplot(ds,hue='embark_town',palette=colors,kind='scatter', diag_kind='hist')

Output:

enter image description here


Or, change to integer dtype:

colors = ['#c994c7','#dd1c77','#c51b8a','#fa9fb5','#9ebcda','#feb24c']

ds = sns.load_dataset('titanic')
ds['adult_male'] = ds['adult_male'].astype(int)
ds['alone'] = ds['alone'].astype(int)
sns.pairplot(ds,hue='embark_town',palette=colors,kind='scatter', diag_kind='hist')

Output:

enter image description here

Related