2012-04-19 39 views
6

我正在繪製一個非正態分佈,使用boxplot並有興趣使用matplotlib的boxplot函數找出異常值。從matplotlib查找異常點:boxplot

除了情節,我有興趣瞭解我的代碼中的點數值,這些點數在boxplot中顯示爲異常值。有沒有什麼辦法可以從boxplot對象中提取這些值用於我的下游代碼?

回答

12

你是指那兩個黑線之上和之下的點嗎?

from pylab import * 
spread= rand(50) * 100 
center = ones(25) * 50 
flier_high = rand(10) * 100 + 100 
flier_low = rand(10) * -100 
data =concatenate((spread, center, flier_high, flier_low), 0) 
r = boxplot(data) 

enter image description here

從儲存箱線圖返回快譯通,你可以從它那裏得到的所有信息,例如:

top_points = r["fliers"][0].get_data()[1] 
bottom_points = r["fliers"][2].get_data()[1] 
plot(np.ones(len(top_points)), top_points, "+") 
plot(np.ones(len(bottom_points)), bottom_points, "+") 

enter image description here