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?
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()
.
Slight simplification of astromax's answer:
plt.errorbar(x,y, yerr=err, capsize=20, elinewidth=3, markeredgewidth=10)
It seems that somehow markeredgewidth is defaulting to 0 sometimes.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.