Seaborn: shrink parameter in histplot shifts data

Created on 9 Feb 2021  路  6Comments  路  Source: mwaskom/seaborn

The smaller the value of the shrink parameter, the more the values in the histogram get shifted towards positive values.

import seaborn as sns
import numpy as np

r = np.random.random(100)

sns.histplot(r);

sns.histplot(r, shrink=0.5);

Screen Shot 2021-02-08 at 10 11 43 PM

Screen Shot 2021-02-08 at 10 15 46 PM

bug distributions

All 6 comments

Thanks for reporting; see #2477

The shrink code had hardcoded parameters for adjusting discrete bins ... IMO it only really makes sense to shrink the bars for discrete histograms, because otherwise there's really no obvious way to tell whether you have shrunken bars or sparse data. But it was bad that it did not prevent or warn you.

The data i had was actually discrete, just not 1,2,3 but instead 0, 0.033, 0.066, 0.100 .... I couldn't use the discrete parameter on it because of that, and i wanted to know exactly where my x points where (If they were left or right from a vertical line). But I think I get it, i should have used more bins instead of the shrink parameter.

I think that a little shrinking with regularly sampled numeric data can make sense, and should now work. (But not using the discrete= kwarg, which sets bins to be centered on integral values). It does sound like you'll need to craft your bins= carefully though.

Yes, I have to set it to an integer multiple of the number of discrete values that I have. Then i should get thinner bins without random shifts.

Keep in mind that by default the left edge of the first bar aligns with the minimum datapoint and the right edge of the last bar aligns with the maximum datapoint. So if you want to use the bar position to encode the discrete values, you'll likely want to employ binrange too.

Oh, I see. Makes sense. Thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sofiatti picture sofiatti  路  4Comments

rrbarbosa picture rrbarbosa  路  3Comments

TDaltonC picture TDaltonC  路  3Comments

stonebig picture stonebig  路  4Comments

vinay-jayaram picture vinay-jayaram  路  3Comments