[Python] Plotly express histogram custom bin size

Discussão em 'Python' iniciado por Stack, Março 27, 2025.

  1. Stack

    Stack Membro Participativo

    I have a data frame with products and their variances that I want to plot as a histogram:

    import pandas as pd
    data = {'product_name': ['link', 'zelda', 'impa', 'rauru', 'saria', 'darunia'], 'variance': [0.95, -0.85, 0.3, 0.2, 0.03, 0.02]}
    df = pd.DataFrame(data)


    I can use plotly to create a histogram:

    px.histogram(df, 'variance')


    [​IMG]

    But I want to create five bins, with custom start and ends (like in the graph below) rather than what plotly defaults to. This seems weirdly difficult to do using plotly express - is there a way to customize the bin sizes at all?

    [​IMG]

    Thanks

    Continue reading...

Compartilhe esta Página