本文介绍了Matplotlib错误栏上限缺少的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在matplotlib中创建带有错误栏的散点图.以下是我的代码的示例:

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!

关于它的价值,我使用的是Ubuntu 13.04,Python 2.7.5 | Anaconda 1.6.1(64位)|和Matplotlib 1.2.1.

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.

这是一个需要覆盖的隐藏rcparam吗?

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)

这篇关于Matplotlib错误栏上限缺少的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 07:22