Srinivas
Srinivas

Reputation: 656

sns.pairplot shows density curve instead of histogram

My understanding is that the below code shall produce histograms in the diagonal boxes. Instead, I am getting density curves? Why is this? If I remove 'hue','palette' and 'diag_kws', it produces histograms as expected. Any inputs?

sns.pairplot(data=ins_pre,
        vars=["fatal_collisions", "premiums",'insurance_losses'],
        kind='scatter',
        hue='Region',
        palette='RdBu',
        diag_kws={'alpha':.5})

plt.show()
plt.clf()

enter image description here

Plot the same data but remove 'hue','palette' and 'diag_kws'

sns.pairplot(data=ins_pre,
        vars=["fatal_collisions", "premiums",'insurance_losses'],
        kind='scatter')

plt.show()
plt.clf()

enter image description here

Upvotes: 3

Views: 3517

Answers (1)

warped
warped

Reputation: 9481

from the documentation:

seaborn.pairplot(data, hue=None, hue_order=None, palette=None, vars=None, x_vars=None, 
y_vars=None, kind='scatter', diag_kind='auto', markers=None, height=2.5, aspect=1,
corner=False, dropna=True, plot_kws=None, diag_kws=None, grid_kws=None, size=None)

[...]

diag_kind{‘auto’, ‘hist’, ‘kde’, None}, optional
Kind of plot for the diagonal subplots. The default depends on whether "hue" is used or not.

So, you should call the function like so:

sns.pairplot(data=ins_pre,
        vars=["fatal_collisions", "premiums",'insurance_losses'],
        kind='scatter',
        hue='Region',
        palette='RdBu',
        diag_kind='hist')

Upvotes: 2

Related Questions