[Python] seaborn histplot output doesn't match with different range

Discussão em 'Python' iniciado por Stack, Maio 11, 2025.

  1. Stack

    Stack Membro Participativo

    I have a dataset and try to plot hist by seaborn:

    sns.histplot(df.query('kms_driven<=100000'),x='kms_driven',binwidth=10000)
    plt.show()


    Output: code1

    First bar has 851 points, second 1266.

    And after that i try to plot another range:

    sns.histplot(df.query('kms_driven<=200000'),x='kms_driven',binwidth=10000)
    plt.show()


    Output: code2

    First bar has 851 points, second is not 1266(seems near 900).

    I try to test this:

    for i in range(0, 200000, 10000):
    a = i
    b = i + 10000
    print(f'{a} - {b}:', df.query('kms_driven<=200000').query('(kms_driven <= @b) & (kms_driven > @a)').kms_driven.count())


    Output:
    0 - 10000: 851
    10000 - 20000: 1266
    20000 - 30000: 1404
    30000 - 40000: 1325
    40000 - 50000: 1180
    50000 - 60000: 963
    60000 - 70000: 753
    70000 - 80000: 528
    80000 - 90000: 345
    90000 - 100000: 231
    100000 - 110000: 125
    110000 - 120000: 137
    120000 - 130000: 28
    130000 - 140000: 11
    140000 - 150000: 24
    150000 - 160000: 6
    160000 - 170000: 2
    170000 - 180000: 2
    180000 - 190000: 2
    190000 - 200000: 0


    It is how must plot histogram. But second bar: 10000 - 20000 is different at 2 pictures.

    Why it is possible?

    Continue reading...

Compartilhe esta Página