-2

I am trying to add the confidence interval 95% on my graph. This code works just fine:

sns.catplot(data=df, x="read_level_1", y="sum_START", kind="box")

However, when I try the following line:

sns.catplot(data=df, x="read_level_1", y="sum_START", errorbar=("ci", 95))

It doesn't work, and I keep getting the following error:

AttributeError: 'PathCollection' object has no property 'errorbar'

Any advice, please?

  • 2
    Seaborn will automatically add error bars with a 95% confidence interval **if there are multiple observations** for a given category. Also, the default for [`catplot`](https://seaborn.pydata.org/generated/seaborn.catplot.html) is `kind='strip'`, it should be `kind='bar'`. You should also update seaborn and matplotlib. `ci` is deprecated / removed. If you're using anaconda, do `conda update --all` at the anaconda prompt for the specific environment. Otherwise update with `pip`. – Trenton McKinney Apr 23 '23 at 13:36

2 Answers2

0

You can replace use of non-existing errorbar with kind and ci arguments respectively. So instead of:

sns.catplot(data=df, x="read_level_1", y="sum_START", errorbar=("ci", 95))

write:

sns.catplot(data=df, x="read_level_1", y="sum_START", kind="bar", ci=95)

BUT... ci seems to be marked deprecated, so I'd rather go for barplot() instead:

sns.barplot(data=df, x="read_level_1", y="sum_START", ci=95)
Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
0

The default kind for catplot is strip but only two kinds (bar and point) can show error bars and, hence, accept the errorbar parameter to control what is shown. A 95% CI is the default value for both so you just need to add kind="point" to your call.

mwaskom
  • 46,693
  • 16
  • 125
  • 127