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()
yusufu
5
@b_prasad26 I have the same problem, @sparkmaddyβs working example doesnβt work for me. Were you able to solve this?
AIMPED
6
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.