[Python] How to align annotation to the edge of whole figure in plotly?

Discussão em 'Python' iniciado por Stack, Janeiro 29, 2025.

  1. Stack

    Stack Membro Participativo

    I know how to align annotation respective to the plotting area (using xref="paper"). I want to place the annotation to right bottom corner of the whole figure. Absolute or relative offset does not work, since the width of the margin outside the plotting area is changing among several figures, depending on their content. Is there a way how to do it? Thanks a ton.

    Edit: Example code

    import plotly.express as px

    fig = px.scatter(x=[1, 2, 3], y=[1, 2, 3], title="Try panning or zooming!")

    fig.add_annotation(text="Absolutely-positioned annotation",
    xref="paper", yref="paper",
    x=0.3, y=0.3, showarrow=False)

    fig.show()


    This annotation is positioned respectively to the origin of the plot, not respectively to the plot edges. [​IMG]

    Continue reading...

Compartilhe esta Página