Seaborn's pairplot seems to have scalling issue on diagonal plots

Viewed 386

Here is the code I tested

import seaborn as sns

tips = sns.load_dataset('tips')
sns.pairplot(tips)

By default, the diagonal plots are all histograms, and everything seems right (see the picgure below). enter image description here

However, when I change the setting of pairplot function to something like below, the scale of the vertical axis of the histograms shrinks while the shape and number of bins are still the same (see the picture below). Does anyone know what happened here? I checked the documentation of the pairplot (https://seaborn.pydata.org/generated/seaborn.pairplot.html), by default, the diag_kind is set to 'auto'. When the kind parameter is equal to scatter (the default setting too), even though diag_kind equals to auto, it will be reset to hist behind the scene (https://github.com/mwaskom/seaborn/blob/master/seaborn/axisgrid.py#L1822). So technically the two scripts I presented here should produce the same histograms. Totally lost here ...

tips = sns.load_dataset('tips', diag_kind='hist')

enter image description here

1 Answers

The reason you're seeing this behaviour is that the diagonal plots will only share the Y with the rest of the row if diag_kind == 'hist'. When diag_kind == 'auto', the diag_sharey parameter to PairGrid is set to False.

I see you're already opened an issue about it on Seaborn's github. I guess a clarification of this behaviour (principle of least astonishment, etc.) in the doc string for diag_kind would be helpful.

Related