How to add error bar with grouped bar plot using Seaborn

Viewed 413

I have calculated 95% confidence interval for my data frame. When adding it to the grouped bar plot using Seaborn, I received an error that yerr must be a scalar or a 1D or (2, n) array-like.

   Linguistic Measure   ML Models   score   ci-b    ci-t    se
0     a                  RF         0.855   0.763   0.946   0.091
1     b                  RF         0.830   0.763   0.898   0.067
2     c                  RF         0.830   0.796   0.864   0.034
3     a                  SVM        0.841   0.823   0.860   0.018
4     b                  SVM        0.831   0.812   0.851   0.019
5     c                  SVM        0.835   0.820   0.850   0.015
6     a                  MLP        0.837   0.801   0.874   0.036
7     b                  MLP        0.810   0.721   0.900   0.089
8     c                  MLP        0.798   0.702   0.894   0.096

I used the code below trying to add error bars to the grouped barplot.

# Draw a nested barplot 
g = sns.catplot(
    data=sample, kind="bar", #update df
    x="Linguistic Measure", y="score", hue="ML Models",
    yerr=sample.pivot(index='Linguistic Measure',columns='ML Models',values='se').values,
    ci=None, palette="BuPu", alpha=.6, height=5)

g.despine(left=True)
g.set_axis_labels("", "score")
g.legend.set_title("")

Then I got error message below:enter image description here

Without adding the error bars, the graph looked fineenter image description here

0 Answers
Related