Skip to content

label_textpositions don't work for shapes #5181

Open
@Mo-Gul

Description

@Mo-Gul

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3backlogbugsomething broken

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions