sbi-dev/sbi

Pairplot sets `num_bins` incorrectly

Closed this issue · 4 comments

Describe the bug
The current version of pairplot generates some weird behvaiour. The example pairplot (attached) was generated using:
pairplot(samples, points = [theta_o], figsize = (5,5),diag_kwargs={"mpl_kwargs":{"bins":50}})
Even when trying to force num_bins, clearly in dimension 2 this is ignored. I am also not sure if the off_diag joint plot is truncated on purpose or not.

pairplot_bug

Thanks for spotting this.

@Matthijspals would you have an idea what it going wrong here?

I will try to have a look later today, but not 100% sure if I manage before I am on holidays. In any case the reason seems to be some interaction between the axis limits and number of bins. I.e. the bottom right plot in your example probably has 50 bins, but over the same range as the top left plot (-3,3). Distinct limits also seem to be responsible for making the off-diagonal plot non-square (which is probably not ideal).

With equal limits:

import torch
from sbi.analysis.plot import pairplot
posterior_samples = torch.randn(1000,2)
theta_o=[1,0]
pairplot(posterior_samples, points = [theta_o], figsize = (5,5),diag_kwargs={"mpl_kwargs":{"bins":50}})

Giving me as expected:
image

However, setting the axis limits to unequal values (and using the same samples):
pairplot(posterior_samples, points = [theta_o], figsize = (5,5),diag_kwargs={"mpl_kwargs":{"bins":50}},limits=[[-1,1],[-4,4]])
image

Or having samples with unequal ranges, and different automatically determined limits:

posterior_samples[:,0]*=10
pairplot(posterior_samples, points = [theta_o], figsize = (5,5),diag_kwargs={"mpl_kwargs":{"bins":50}})

image

gives unwanted behaviour.

Thanks for the tip! Seems like you're right. I can quickly fix this myself.

Regarding the non-square off-diagonal plot, a quick fix is passing:
offdiag_kwargs={"mpl_kwargs":{"aspect":'auto'}}
but this should probably be the default setting (this can be done using the _get_default_offdiag_kwargs function)