Bayu Setiawan
Bayu Setiawan

Reputation: 13

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

Upvotes: 1

Views: 1347

Answers (1)

Hamzah Al-Qadasi
Hamzah Al-Qadasi

Reputation: 9786

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"]})

Upvotes: 1

Related Questions