Skip to content
Advertisement

Is it possible to input values for confidence interval/ error bars on seaborn barplot?

I’m used to doing my barplots on seaborn and I like it’s layout for showing confidence bars, but I have a special case in a dataset where I already have the confidence interval, like this:

JavaScript

Is there a way to manually input the values for seaborn confidence interval lines? Or to use it as “None” and use some matlib function to put the confidence interval in the graph (but keeping seaborn’s barplot)

When I do:

JavaScript

I get, as expected, a normal barplot:

This graphic

And when I attempt to use matlib’s error bar like this:

JavaScript

Everything get’s messed up with just one strange line lost in the figure:

Like this graphic

Am I using errorbar wrong? Is there a better tool for this?

Advertisement

Answer

Update (August 2, 2019):

My earlier answer (see below) overstates the error because yerr uses the same error for the top and bottom if passed a single array of shape (N,). To get different errors for the bottom and top, we need to use an array of shape (2, N). The first row is used for the bottom error and the second for the top (from the documentation. In code this is:

JavaScript

The result is below: enter image description here

The errors are now different on the bottom and top.

Following is a direct comparison, with the original (symmetrical) error bars in red and the non-symmetrical error bars in blue. We can directly see the differences:

enter image description here

Earlier Answer with Exaggerated Errors

The months are being interpreted differently by seaborn and matplotlibresulting in odd placement of the error bars. You also need to specify fmt='none' to avoid having errorbar plot data points as a line. The following code places the errors bars at the correct x locations:

JavaScript

enter image description here

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement