Can't able to reorder y-axis bar position

Hi, Can anyone tell me how to reorder the y-axis labels in the horizontal bar chart?

The code that I am using to create the plot -

fig = go.Figure()
fig.add_trace(go.Bar(x = banner_pos_prob[1], y= banner_pos_prob.index, orientation='h'))
fig.update_layout(title="Banner Position Click Probability",
                  xaxis=dict(title="probabilities"),
                  yaxis=dict(title="Banner Position"))
fig.update_yaxes(categoryorder= "array",
                 categoryarray= [7, 4, 1, 3, 0, 5, 2])
fig.show()

As you can see I tried to update the y-axis bar position, but it is not reflecting in the plot.

I am trying to plot the bars in descending order from top to bottom.

Hi @b_prasad26

Could you try this line:

fig.update_layout(barmode='stack', yaxis={'categoryorder':'total ascending'})

This would help you to have the longest bar at the top and the smallest one below.

@sparkmaddy it’s not working.

Hi @b_prasad26

This is my working example.

import plotly.graph_objects as go

fig = go.Figure(go.Bar(
            x=[20, 14, 23],
            y=['giraffes', 'orangutans', 'monkeys'],
            orientation='h'))


fig.update_layout(title="Banner Position Click Probability",
                  xaxis=dict(title="probabilities"),
                  yaxis=dict(title="Banner Position"))

fig.update_layout(barmode='stack', yaxis={'categoryorder':'total ascending'})

fig.show()

@b_prasad26 I have the same problem, @sparkmaddy’s working example doesn’t work for me. Were you able to solve this?

Hi @yusufu. Maybe it would be better to open a new topic instead of reviving a two year old thread. Maybe the OP is not active on the forums anymore.