from matplotlib import pyplot as plt
import pandas as pd
import seaborn as sns
df = pd.DataFrame({})
df[soi_name]=soi
df[outcome_name]=outcome
soi,outcome = utils.format_cols(soi, outcome,'continuous',agg_method)
sns.factorplot(data=df, x=outcome_name,y=soi_name,hue=outcome_name,kind='box')
plt.savefig(ofilepath)
So the code snippet used to generate this boxplot is just above. outcome is a binary float type pandas series. soi is a float type pandas series. This x-axis shift occurs for boxplots and violinplots. When I generate factor plots with the following code:
df = pd.DataFrame({})
df[soi_name]=soi
df[outcome_name]=outcome
sns.factorplot(data=df, x=outcome_name,y=soi_name,hue=outcome_name)
plt.savefig(ofilepath)
...
I get my desired outputs. Any ideas with why the shift for the box plots might be happening?
We can turn the boxplot into a horizontal boxplot by two methods first, we need to switch x and y attributes and pass it to the boxplot( ) method, and the other is to use the orient=”h” option and pass it to the boxplot() method.
To remove outliers from a seaborn boxplot then set the fliersize parameter to 0. By detro - Last Updated Aug. 22, 2022, 10:11 a.m.
Draw a box plot to show distributions with respect to categories. A box plot (or box-and-whisker plot) shows the distribution of quantitative data in a way that facilitates comparisons between variables or across levels of a categorical variable.
You have two different hue
s, such that the first is plotted left of the position and the second is plotted right of the position. This is usually desired, see e.g. this plot from the documentation
import matplotlib.pyplot as plt
import seaborn as sns
tips = sns.load_dataset("tips")
ax = sns.boxplot(x="day", y="total_bill", hue="time",
data=tips, linewidth=2.5)
plt.show()
Here, you wouldn't want to have the blue and orange boxplots overlapping, would you?
But you can, if you want. Use the dodge=False
argument for that purpose.
import matplotlib.pyplot as plt
import seaborn as sns
tips = sns.load_dataset("tips")
ax = sns.boxplot(x="day", y="total_bill", hue="time",
dodge=False, data=tips, linewidth=2.5)
plt.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With