When using FacetGrid.map
, anything that refers to the data
DataFrame must be passed as a positional argument. This will work in your case because yerr
is the third positional argument for plt.errorbar
, though to demonstrate I’m going to use the tips dataset:
from scipy import stats
tips_all = sns.load_dataset("tips")
tips_grouped = tips_all.groupby(["smoker", "size"])
tips = tips_grouped.mean()
tips["CI"] = tips_grouped.total_bill.apply(stats.sem) * 1.96
tips.reset_index(inplace=True)
I can then plot using FacetGrid
and errorbar
:
g = sns.FacetGrid(tips, col="smoker", size=5)
g.map(plt.errorbar, "size", "total_bill", "CI", marker="o")
However, keep in mind that the there are seaborn plotting functions for going from a full dataset to plots with errorbars (using bootstrapping), so for a lot of applications this may not be necessary. For example, you could use factorplot
:
sns.factorplot("size", "total_bill", col="smoker",
data=tips_all, kind="point")
Or lmplot
:
sns.lmplot("size", "total_bill", col="smoker",
data=tips_all, fit_reg=False, x_estimator=np.mean)