Ordering a Plotly/Express Boxplot in a defined order along the x-axis

I’ve got a dataframe that contains real-estate data by state and I want to create a boxplot and order the boxplots for each state in decreasing order of their medians. This is easy to do using Seaborn as:

Here I do a groupby on “state” and sort by the mean of the sales prices at the county level

my_order = rfin_weekly_raw.groupby(by=[“state”])[“median_sale_price”].mean().sort_values(ascending=False).index

then, I create the boxplot with Seaborn and subsequently do some formatting of the graph components

box_plot1 = sns.boxplot(x = ‘state’,y = ‘median_sale_price’,data = rfin_weekly_raw, order=my_order)

I’ve tried doing the equivalent in Plotly/Express but I can find a ways to order the individual state boxplots the way I want them.

Any ideas on how I can achieve this?

Hi,

You can check out this answer. Simply add ascending=False as an argument of sort_values().