[Python] Bars not fitting to X-axis ticks in a Seaborn distplot

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

  1. Stack

    Stack Membro Participativo

    I do generate that figure with seaborn.distplot(). My problem is that the ticks on the X-axis do not fit to the bars, in all cases. I would expect a relationship between bars and ticks like you can see at 11 and 15.

    [​IMG]

    This is the MWE

    import numpy as np
    import pandas as pd
    import seaborn as sns

    # Data
    np.random.seed(42)
    n = 5000
    df = pd.DataFrame({
    'PERSON': np.random.randint(100000, 999999, n),
    'Fruit': np.random.choice(['Banana', 'Strawberry'], n),
    'Age': np.random.randint(9, 18, n)
    })

    fig = sns.displot(
    data=df,
    x='Age',
    hue='Fruit',
    multiple='dodge').figure

    fig.show()

    Continue reading...

Compartilhe esta Página