Sort stacked bar chart's traces/layers by value

Hello!

Is it possible to sort the individual column based layers in a stacked bar chart (similar to layout.axis.categoryorder)?

Take this fiddle for example: https://codepen.io/plotly/pen/bdZbWy

I would like to have the data be represented in this way:

(notice that in the case of orangutans and monkeys the LA zoo is at the bottom).

I come from chart.js where in order to get this functionality I had to mess about with creating a custom plugin and was hoping that plot.ly would have a more elegant solution.

Thanks

We don’t offer an easy way to do this unfortunately. Traces are stacked according to their place in the input data array.

The easiest workaround I can think of is: https://codepen.io/etpinard/pen/xxKaMYK?editors=1010

where the two traces are combined into one and we make use of sort transform.

Here is a nice solution in python: