[Python] How to make Plotly figure legend be right to left instead of left to right

Discussão em 'Python' iniciado por Stack, Abril 20, 2025.

  1. Stack

    Stack Membro Participativo

    I have this plot with horizontal legend. I want the legend title to be on the right instead of the left, and I want the bullets of each legend item to be on the right of the name instead of on the left. How can I do this? Thank you!

    import plotly.express as px
    long_df = px.data.medals_long()
    fig = px.bar(long_df, x="nation", y="count", color="medal")
    fig.update_layout(legend=dict(orientation="h", yanchor="bottom", y=1.01,
    xanchor="left", x=0.35, title=":Medal"))
    fig.show()

    Continue reading...

Compartilhe esta Página