plotly.py icon indicating copy to clipboard operation
plotly.py copied to clipboard

`label_textpositions` don't work for shapes

Open Mo-Gul opened this issue 8 months ago • 1 comments

It is written that now the recommended way of adding text annotations to shapes is by adding labels. But for that the textposition is only working for ["start", "middle", "end"].

Here an MWE:

import plotly.express as px

fig = px.scatter(y=[0, 11])
# REF: <https://plotly.com/python/reference/layout/shapes/#layout-shapes-items-shape-label-textposition>
positions = [
    "top left", "top center", "top right",
    "middle left", "middle center", "middle right",
    "bottom left", "bottom center", "bottom right",
    "start", "middle", "end",
]
for i, position in enumerate(positions):
    fig.add_hline(
        y=i,
        label=dict(
            text=position,
            textposition=position,
            font_color="red",
        ),
        line_color="red",
    )
    # # same for vertical lines
    # fig.add_vline(
    #     x=i,
    #     label=dict(
    #         text=position,
    #         textposition=position,
    #         font_color="green",
    #     ),
    #     line_color="green",
    # )
    )

which gives

Image

Mo-Gul avatar May 13 '25 12:05 Mo-Gul

thanks @Mo-Gul - I agree this would be a useful fix, but we're unlikely to be able to get to it any time soon. if you or anyone else from the community would like to submit a fix, I can try to prioritize review. thanks again - @gvwilson

gvwilson avatar May 20 '25 14:05 gvwilson