gpt4 book ai didi

python - 为什么我用 plotly 给箱线图上色时箱线图变窄了?

转载 作者:行者123 更新时间:2023-12-01 21:34:43 29 4
gpt4 key购买 nike

我正在尝试使用 plotly.express 作为箱线图来绘制存储在 pandas DataFrame 中的数据。 df 如下所示:

enter image description here


这是我在 plotly 中制作基本箱线图的代码:

import plotly.express as px

fig = px.box(df1, x="Condition",
y="Number of Groups")
fig.show()

结果给出了我正在寻找的那种图表: enter image description here

现在,我想根据我的使用情况为每个条件涂上不同的颜色:

import plotly.express as px

fig = px.box(df1, x="Condition",
y="Number of Groups",
color="Condition")
fig.show()

给我这张图,现在箱形图比正常情况下窄得多。有谁知道如何避免这种情况?谢谢 enter image description here

最佳答案

这是一个已在 plotly 4.8 版中修复的错误,以下版本的解决方法是在 中添加 boxmode="overlay" px.box()color 设置为与 x 相同的值时调用。我应该补充一点,这同样适用于 px.violinpx.strip 使用 violinmodestripmode 的绘图,分别:)

关于python - 为什么我用 plotly 给箱线图上色时箱线图变窄了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62130499/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com