Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib Errorbar Caps Missing

I'm attempting to create a scatter plot with errorbars in matplotlib. The following is an example of what my code looks like:

import matplotlib.pyplot as plt import numpy as np import random  x = np.linspace(1,2,10) y = np.linspace(2,3,10) err = [random.uniform(0,1) for i in range(10)]  plt.errorbar(x, y,        yerr=err,        marker='o',        color='k',        ecolor='k',        markerfacecolor='g',        label="series 2",        capsize=5,        linestyle='None') plt.show() 

The problem is the plot which is output contains no caps at all! enter image description here

For what it's worth, I'm on Ubuntu 13.04, Python 2.7.5 |Anaconda 1.6.1 (64-bit)|, and Matplotlib 1.2.1.

Could this be a hidden rcparam that needs to be overwritten?

like image 214
astromax Avatar asked Aug 25 '13 22:08

astromax


People also ask

How do I get Matplotlib error bars?

Error bars can also be added to line plots created with Matplotlib. The ax. errorbar() method is used to create a line plot with error bars.

Which of the following parameter is used to set the color of a error bar in bar plots?

ecolor: This parameter is an optional parameter. And it is the color of the errorbar lines with default value NONE.


2 Answers

What worked for me was adding this (as per: How to set the line width of error bar caps, in matplotlib):

(_, caps, _) = plt.errorbar(x,y, yerr=err, capsize=20, elinewidth=3)  for cap in caps:     cap.set_color('red')     cap.set_markeredgewidth(10) 
like image 136
astromax Avatar answered Sep 23 '22 16:09

astromax


It has to do with the rcParams in matplotlib. To solve it, add the following lines at the beginning of your script:

import matplotlib matplotlib.rcParams.update({'errorbar.capsize': 2}) 

It also works with plt.bar().

like image 27
Lucho Avatar answered Sep 24 '22 16:09

Lucho