Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从matplotlib中的bar对象检索YER值_Matplotlib_Subplot - Fatal编程技术网

从matplotlib中的bar对象检索YER值

从matplotlib中的bar对象检索YER值,matplotlib,subplot,Matplotlib,Subplot,如何从ax.bar对象检索yerr值? 条形图是用一条直线创建的,ax.bar()的每个参数都是一个集合,包括yerr值 bar_list = ax.bar(x_value_list, y_value_list, color=color_list, tick_label=columns, yerr=confid_95_list, align='center') 稍后,我希望能够检索图表中每个条形图的y值和YER值。 我遍历bar_列表集合,可以检索y值,但不

如何从ax.bar对象检索yerr值? 条形图是用一条直线创建的,ax.bar()的每个参数都是一个集合,包括yerr值

bar_list = ax.bar(x_value_list, y_value_list, color=color_list,
                  tick_label=columns, yerr=confid_95_list, align='center')
稍后,我希望能够检索图表中每个条形图的y值和YER值。 我遍历bar_列表集合,可以检索y值,但不知道如何检索yerr值

bar_list = ax.bar(x_value_list, y_value_list, color=color_list,
                  tick_label=columns, yerr=confid_95_list, align='center')
获取y值如下所示:

for bar in bar_list:
    y_val = bar.get_height()
我怎样才能拿到耶尔?是否有类似于bar.get\yerr()的方法?(它不是酒吧。get_yerr()) 我希望能够:

for bar in bar_list:
    y_err = bar.get_yerr()

请注意,在上述示例中,
confid_95_list
已经是错误列表。因此,没有必要从绘图中获取它们

回答问题:在条形图列表中条形图的
行中,
条形图是一个
矩形,因此没有与之关联的errorbar

但是
bar\u list
是一个带有属性
errorbar
的条形容器,其中包含errorbar创建的返回。然后可以获取线集合的各个线段。每一行从
yminus=y-y_error
yplus=y+y_error
;测线集合仅存储点
yminus
yplus
。例如:

means = (20, 35)
std = (2, 4)
ind = np.arange(len(means))   

p = plt.bar(ind, means, width=0.35, color='#d62728', yerr=std)

lc = [i for i in p.errorbar.get_children() if i is not None][0]
for yerr in lc.get_segments():
    print (yerr[:,1]) # print start and end point
    print (yerr[1,1]- yerr[:,1].mean()) # print error
将打印

[ 18.  22.]
2.0
[ 31.  39.]
4.0
[ 18.  25.]
[-2.  5.]
[ 31.  38.]
[-4.  3.]
所以这对对称误差条很有效。对于不对称误差条,您还需要考虑点本身

means = (20, 35)
std = [(2,4),(5,3)]
ind = np.arange(len(means))   

p = plt.bar(ind, means, width=0.35, color='#d62728', yerr=std)

lc = [i for i in p.errorbar.get_children() if i is not None][0]
for point, yerr in zip(p, lc.get_segments()):
    print (yerr[:,1]) # print start and end point
    print (yerr[:,1]- point.get_height()) # print error
将打印

[ 18.  22.]
2.0
[ 31.  39.]
4.0
[ 18.  25.]
[-2.  5.]
[ 31.  38.]
[-4.  3.]
最后,这似乎是不必要的复杂,因为您只检索最初输入的值,
意味着
std
,您可以简单地将这些值用于任何您想做的事情