[Python] Adding vertical lines to histogram plot

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

  1. Stack

    Stack Membro Participativo

    I have the following code to plot a histogram in Python:

    fig.add_trace(go.Histogram(x = df["error"], showlegend = False))

    This results into a histogram similar to:

    [​IMG]

    Now I want to add 2 vertical lines to the plot at x = target and x = -target, to create something similar like:

    [​IMG]

    I currently have the following code:

    fig.add_trace(go.Scatter(x=[target, target], y=[0, ymax],
    mode='lines', name='target', line=dict(color='grey', dash='dash'),
    legendgroup='target', showlegend=True))
    fig.add_trace(go.Scatter(x=[-target, -target], y=[0, ymax],
    mode='lines', name='target', line=dict(color='grey', dash='dash'),
    legendgroup='target', showlegend=False))


    However, I am not sure how I can retrieve the required ymax value from the histogram plot.

    Continue reading...

Compartilhe esta Página