如何在绘图表达箱线图中按月份更改/排序条形位置作为颜色?

发布于 2025-01-15 06:32:19 字数 799 浏览 3 评论 0原文

朋友们 我试图将我的数据绘制成箱线图。

这是我的数据

数据

这是箱线图

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()

我的问题是,我想对位置进行排序条形按月份作为颜色。 我想将“FEBRUARY”颜色移到“MARCH”颜色之前

graphic

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墟烟 2025-01-22 06:32:21

如果您查看文档,您将看到有一个名为 category_orders 的属性。您可以这样添加订单:

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

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"]})
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文