Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Splitting data into bins in histplot

I have a problem with sns.histplot(). As far as I understand bins parameter should indicate how many of bins should be in the plot. Here is some code to visualize the strange (at least for me) behavior.

    d = {'col1': [1, 2, 3, 4, 5, 6, 7, 8, 9 , 10 , 11 , 12, 13, 14, 15], 'col2': [1, 1, 1, 1, 1, 1, 2, 2, 2 , 2 , 2, 2, 2, 2, 2]}
    df = pd.DataFrame(data=d)
    sns.histplot(data=df, x='col1', multiple='dodge', hue='col2', binwidth=2, bins=8)

Example

I have almost same problem in my original code where i have

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

hist = sns.histplot(data=Data, x=y_data, multiple='dodge', ax=axes[0], hue=i[2][1], binwidth=2, bins=10)

Original histogram
And as You can see there is only one bin where data have its minimum and std but is not splitted into number of bins I declared. Can anyone explain me why this is not splitting data into provided number of bins ? How can I change code to ensure constant number of bins ?

>Solution :

I think the problem is binwidth parameter. Maybe just try to delete that parameter, or set it to smaller value (0.2 or 0.1)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading