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!
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?
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.
ecolor: This parameter is an optional parameter. And it is the color of the errorbar lines with default value NONE.
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)
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()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With