1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Reverse categories order in hovermode on Plotly

Discussão em 'Python' iniciado por Stack, Setembro 23, 2024.

  1. Stack

    Stack Membro Participativo

    I have a Plotly stacked barplot with specific categories order. On the plot, the categories stack from bottom to top as wanted : bronze, silver, gold.

    However, it stacks on the reversed order on the hovermode : gold, silver and bronze (from bottom to top as well)

    Is there any way to correct the order in the hovermode "x unified" ?

    import plotly.express as px

    long_df = px.data.medals_long()

    category_orders = {
    "medal": [
    "bronze",
    "silver",
    "gold",
    ]
    }

    fig = px.bar(long_df, x="nation", y="count", color="medal", category_orders=category_orders)
    fig.update_layout(hovermode="x unified", legend=dict(orientation="h"))
    fig.show()

    Continue reading...

Compartilhe esta Página