2014-05-14 21 views
7

Bir kutu çizimi yapmam (Python ve matplotlib'de) ancak orijinal "ham" verilere sahip değilim. Elimde maksimum, min, ortalama, ortanca ve IQR (normal dağılım) için önceden hesaplanmış değerler var ancak yine de bir kutu çizimi yapmak istiyorum. Tabii ki, aykırı aylaklar mümkün değil, ama sanırım bütün bilgiler orada.Önceden hesaplanmış (özet) istatistikleri kullanan Matplotlib boxplot

Başarısız bir yanıt bulmak için her yeri araştırıyorum. Geldiğim en yakın soru aynı soru ama R için (bilmediğim). Bkz. Is it possible to plot a boxplot from previously-calculated statistics easily (in R?)

Kimse bana kutu plotunu nasıl yapılacağını gösterebilir mi?

Çok teşekkürler! bireysel boxplot unsurları chancing tarafından bunu elle eski sürümlerinde

+1

Bu işlevsellik, ana dal üzerinde bulunan ve etiketli gereken (1.4 olacak 'yakında'). https://github.com/matplotlib/matplotlib/pull/2643 – tacaswell

cevap

6

, sen var: Ben gerekli belgeleri bulup gelmek başardı @tacaswell ait yorumuna

Mean=[3.4] #mean 
IQR=[3.0,3.9] #inter quantile range 
CL=[2.0,5.0] #confidence limit 
A=np.random.random(50) 
D=plt.boxplot(A) # a simple case with just one variable to boxplot 
D['medians'][0].set_ydata(Mean) 
D['boxes'][0]._xy[[0,1,4], 1]=IQR[0] 
D['boxes'][0]._xy[[2,3],1]=IQR[1] 
D['whiskers'][0].set_ydata(np.array([IQR[0], CL[0]])) 
D['whiskers'][1].set_ydata(np.array([IQR[1], CL[1]])) 
D['caps'][0].set_ydata(np.array([CL[0], CL[0]])) 
D['caps'][1].set_ydata(np.array([CL[1], CL[1]])) 
_=plt.ylim(np.array(CL)+[-0.1*np.ptp(CL), 0.1*np.ptp(CL)]) #reset the limit 

enter image description here

+0

Çok teşekkürler! Çalışanlar gerçekten çok güzel. –

7

Teşekkür Matplotlib 1.4.3 kullanarak bir örnekle. Ancak, bu örnek şekli otomatik olarak doğru boyuta ölçeklendirmez. belgelerine

import matplotlib.pyplot as plt 

item = {} 

item["label"] = 'box' # not required 
item["mean"] = 5 # not required 
item["med"] = 5.5 
item["q1"] = 3.5 
item["q3"] = 7.5 
#item["cilo"] = 5.3 # not required 
#item["cihi"] = 5.7 # not required 
item["whislo"] = 2.0 # required 
item["whishi"] = 8.0 # required 
item["fliers"] = [] # required if showfliers=True 

stats = [item] 

fig, axes = plt.subplots(1, 1) 
axes.bxp(stats) 
axes.set_title('Default') 
y_axis = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 
y_values = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"] 
plt.yticks(y_axis, y_values) 

ilgili bağlantılar: