[Python] Delta/Difference Histogram

Discussão em 'Python' iniciado por Stack, Julho 22, 2025.

  1. Stack

    Stack Membro Participativo

    Minimum working example:

    import pandas as pd
    import plotly.graph_objects as go

    # Example data
    data = {
    "data-a": [10, 15, 10, 20, 25, 30, 15, 10, 20, 25],
    "data-b": [12, 18, 14, 22, 28, 35, 17, 13, 21, 27]
    }
    df = pd.DataFrame(data)

    # Create the figure
    fig = go.Figure()
    fig.add_trace(go.Histogram(x=df["data-a"], name="Data A"))
    fig.add_trace(go.Histogram(x=df["data-b"], name="Data B", opacity=0.5))
    fig.update_layout(font_size=15)
    fig.update_yaxes(title_text="Count")
    fig.show()


    The result:

    [​IMG]

    I now want to create a new histogram that is basically depicting the difference in counts between both histograms (same X-axis and bins), so in this case that should be something like:

    [​IMG]

    Continue reading...

Compartilhe esta Página