'How to changet/sort the position of bar by MONTH as a color in plotly express boxplot?

friends Im trying to plot my data to a boxplot.

this is my data

data

this is the boxplot graph

import plotly.express as px

fig = px.box(df_hb, x="QUESTION DETAIL", y="ANSWER", color="MONTH", title="Buy Price", points="outliers", 
             labels={"QUESTION DETAIL" : "Product", "ANSWER" : "Buy Price"})
fig.update_traces(quartilemethod="exclusive") # or "inclusive", or "linear" by default
fig.update_layout(paper_bgcolor='white',
                  plot_bgcolor='white',
                  autotypenumbers='convert types',
                  legend_traceorder="normal"
)
fig.show()

my problem is, i want to sort the position of bar by the month as a color. i want to move "FEBRUARY" color before "MARCH" color

graphic



Solution 1:[1]

If you look at the documentation, you will see there is an attribute called category_orders. You can add the order like that:

px.box(......,category_orders={"MONTH": ["FEBRUARY-2022", "MARCH-2022"]})

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Phoenix