I'm looking to get the sample number to appear on each boxplot as I see here: https://python-graph-gallery.com/38-show-number-of-observation-on-boxplot/
I'm able to get the median and counts in lists as the link above presents. However, I have a factorplot with hue, such that the positions of the x-ticks don't seem to be captured on the x-axis.
Using the seaborn tips data set, I have the following:
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
sns.set_style("whitegrid")
tips = sns.load_dataset("tips")
g = sns.factorplot(x="sex", y="total_bill",hue="smoker",
col="time",data=tips, kind="box",size=4, aspect=.7)
# Calculate number of obs per group & median to position labels
medians = tips.groupby(['time','sex','smoker'])['total_bill'].median().values
nobs = tips.groupby(['time','sex','smoker']).size()
nobs = [str(x) for x in nobs.tolist()]
nobs = ["n: " + i for i in nobs]
plt.show()
I'd like to get the "n: [# of observations]" right above the median, and I'm wondering if there's a way to get that x-tick. Also, assume some groups don't always have both male and female so it can't just be hard coded.