Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
576 views
in Technique[技术] by (71.8m points)

python - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...