Seaborn 中的偏心 X 轴

Off-center X-Axis in Seaborn

我在让箱线图与 x 轴标签对齐时遇到问题。我试过调整图表的大小,但数据点看起来还是有点偏差。感谢您的帮助!

这是当前图表:

如果没有 MCVE, But I'm guessing it's because you're using two categorical variables; x, and hue. This creates a so called "nested"(搜索关键字 "smoke")箱线图很难判断,如果其中一个类别在某种意义上为空,可能会导致观察到的偏差设置。
再一次,只是猜测,因为那是你给我们的。
祝你好运!

设置 hue 参数时可能会发生这种错位。

您可以将 dodge=False 参数添加到 sns.boxplot 函数以保持箱线图与 x-axis 标签对齐。

在您的示例中,它看起来像这样:

sns.boxplot(x=df["Groups"], y=df["Rate per Month"], hue=df["Hours per Month"], dodge=False)

seaborn.boxplot 文档中 dodge 参数的说明:

dodge: bool, optional

When hue nesting is used, elements should be shifted along the categorical axis.

Example 来自 seaborn.boxplot 文档。