'Off-center X-Axis in Seaborn
Solution 1:[1]
It's hard to tell without an MCVE, But I'm guessing it's because you're using two categorical variables; x
, and hue
. This creates a so called "nested" (search for the key-word "smoke") box-plot, and if one of the categories is empty in some sense might cause the observed off-set.
Again, only guessing 'cause that's what you gave us.
Good luck!
Solution 2:[2]
This misalignment can happen when the hue
argument is set.
You can add the dodge=False
argument to the sns.boxplot
function to keep boxplots aligned with the x-axis labels.
In your example, it would look like this:
sns.boxplot(x=df["Groups"], y=df["Rate per Month"], hue=df["Hours per Month"], dodge=False)
Description of the dodge
parameter from the the seaborn.boxplot documentation:
dodge: bool, optional
When hue nesting is used, elements should be shifted along the categorical axis.
Example from the seaborn.boxplot documentation.
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 | ShlomiF |
Solution 2 | njmarko |