2015-08-03 51 views
0

我想绘制一组不同颜色的错误栏。我的数据点也有不同的颜色。Matplotlib错误栏使用for循环(用于不同的颜色)

目前我使用:

colours = ['r','b','g','k','m'] 
labels = ['200Mpc','300Mpc','340Mpc','400Mpc','450Mpc'] 

fig2 = plt.figure(figsize=(7,5)) 
ax3 = fig2.add_subplot(111) 
for a,b,c,d,e,f in zip(r0_array,gamma_array,r0_error,gamma_error,colours,labels): 
    ax3.scatter(r0_array,gamma_array,c=e,label=f) 
    ax3.errorbar(r0_array,gamma_array,xerr=c,yerr=d,fmt='o',color=e) 
ax3.set_xlabel('$r_{0}$',fontsize=14) 
ax3.set_ylabel(r'$\gamma$',fontsize=14) 
ax3.legend(loc='best') 
fig2.show() 

导致与errorbars和色彩的人物被overplotted。

enter image description here

我可以看到for循环再次被运行5次,因为我可以看到所有的颜色,但我不明白为什么会这样!

回答

0

我想出了我做的非常愚蠢的错误!

for循环,每一个值,即A,B,C,d,E,F取的值内的阵列r0_array,gamma_array等后..

而不是调用在scattera,b,c,d的,我我每次都调用整个数组r0_array, gamma_array,etc..

for a,b,c,d,e,f in zip(r0_array,gamma_array,r0_error,gamma_error,colours,labels): 
     ax3.scatter(a,b,color=e,label=f) 
     ax3.errorbar(a,b,xerr=c,yerr=d,fmt='o') 

固定的问题。