Flipping horizontal bar chart to descending order

hi!
i’ve built a bar chart that is currently using a 'orientation = ‘h’ parameter to make it a horizontal bar chart instead of vertical. The bars go from left to right instead of bottom to top. This works fine but its building the chart with the smallest bar (lowest value) at the top, when i want it to be at the bottom. I’d like it to be in descending order.

Am wondering if there’s a way to do this without manipulating the data with pandas to be sorted in descending order.
Here’s the code I have. I’ve also attached an image. Thank you

def categoryChart():
    return { 'data': [
        graph_objs.Bar(
            x = count,
            y = category,
            orientation = 'h',
            marker = dict(
                line = dict(color='#ffffff', width=1)
                ),
            ),
        ],
        'layout': graph_objs.Layout(
            font=dict(size=10),
            xaxis=dict(tickangle=-25, automargin=True),
            yaxis=dict(showticklabels=True, automargin=True),
            margin = dict(t=20, b= 20, r=10),
            )
        }
1 Like
yaxis=dict(autorange="reversed")

Use this in your layout.

(Your question is probably duplicate. There was a similar discussion with solution Horizontal Bar Charts)

5 Likes

awesome, this did the trick. thank you @caiyij

hi, great feature, but what if you have two horizontal bars, and want one of the be flipped, like attached Capture



figure = make_subplots(rows=1, cols=2,shared_yaxes=True)
	figure.add_trace(go.Bar(
		            x=[20, 14, 23, 15, 26, 37,12],
		            y=['a', 'b', 'c', 'd', 'e', 'f', 'g'], orientation='h'), row = 1, col = 1, )
figure.add_trace(go.Bar(
	            x=[20, 14, 23, 15, 26, 37,12],
	            y=['a', 'b', 'c', 'd', 'e', 'f', 'g'], orientation='h' ),
				row = 1, 
				col = 2)
1 Like