2013-05-27 167 views
3

我正在嘗試繪製一個errorbar圖,其中每個錯誤欄可以是紅色或綠色,具體取決於用於計算條的統計信息是否顯着。
我嘗試使用顏色數組作爲c參數的輸入,但這並不奏效。使用不同顏色爲每個錯誤條顏色

有誰知道該怎麼做?

下面是代碼,我到目前爲止有:

yerrs = np.array([quantiles[:,2],quantiles[:,3]]) 
print yerrs.shape 
colors = ['r', 'b'] * (yerrs.shape[1]/2) 
fig, axes = plt.subplots(nrows=2, sharex=True, sharey=True) 
axes[0].errorbar(quantiles[:,0],quantiles[:,1], yerr=yerrs, c=colors) 
axes[0].axhline(0, color='black') 
axes[0].axvline(0, color='black') 
axes[0].set_title('Fitted dist') 

然後我得到的錯誤:

ValueError: to_rgba: Invalid rgba arg "['r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b', 'r', 'b']" 
could not convert string to float: r 
+0

剛剛添加我的代碼 – user1094206

回答

5

單獨的數據陣列分成兩組,並使用「易彩」指定errorbar顏色。

axes[0].errorbar(x1, y1, yerr=yerr1, ecolor="r") 
axes[0].errorbar(x2, y2, yerr=yerr2, ecolor="b") 

如何將數據分成部分1和2應該是微不足道的給你,但讓我知道,如果你是不確定的。

+0

謝謝!這幾乎正​​是我想要做的,除了連接點的線對於每個圖是分開的。如果他們可以在同一條線上,會很棒。 – user1094206

+0

@ user1094206不確定你的意思是什麼---你希望它們在同一行上,然後使用相同的x和y而不是x1/2和y1/2來繪製它們。 – nye17