2016-07-05 77 views
0

我正在用matplotlib創建boxplot。我如何獲得盒子裏的積分?獲得箱內積分

import matplotlib.pyplot as plt 

data = [2,4,5,62,57,3,8,3,96,2,34,43] 

box=plt.boxplot(data) 
+0

哪點?做什麼?更精確。 – sascha

+0

http://blog.contextures.com/wp-content/uploads/2013/06/boxplotsimple08.png查看圖片。謝謝 – dijiri

+0

沒有真正回答我的問題。 – sascha

回答

0

盒子內的點是位於所述四分位範圍內的值。第一和第三四分可以np.quartile進行計算,一旦你知道這些值,您可以有條件地品嚐你的數據數組:

import matplotlib.pyplot as plt 
import numpy as np 

data = np.array([2,4,5,62,57,3,8,3,96,2,34,43]) 

box=plt.boxplot(data) 

# Get all the data between the 1st and 3rd quartile 
data_iqr = data[ (data > np.percentile(data, 25)) & (data < np.percentile(data, 75)) ] 

# Visual confirmation: 
plt.scatter(np.ones_like(data_iqr), data_iqr, marker='o', label='IQR') 
plt.scatter(np.ones_like(data),  data,  marker='x', label='all') 
plt.legend(frameon=False, loc='best') 

enter image description here