2011-12-30 3 views
7

파이썬과 Matplotlib을 사용하여 EPSgram (아래 참조)을 플로팅하고 싶습니다.Python-Matplotlib 상자 그림. 백분위 수를 0, 25, 50, 75, 90 및 100으로 표시하는 방법?

boxplot 함수는 사 분위수 (0, 25, 50, 75, 100) 만 표시합니다. 그래서 두 개의 상자를 추가하려면 어떻게해야합니까? 당신은 여전히 ​​호기심이 있다면

EPSGram boxplot

+2

내가 이렇게 쉬운 방법이 있다고 생각하지 않지만, 당신은 몇 가지'broken_barh'를 사용하여 자신에게 할 아마 수 . – aganders3

+5

표현의 대안으로 [violin plot] (http://pyinsci.blogspot.com/2009/09/violin-plot-with-matplotlib.html)을 고려해보십시오. –

답변

2

나는 함께 샘플을 넣어. 그것은 scipy.stats.scoreatpercentile 사용하지만 다른 곳에서 그 숫자를 받고있을 수 있습니다

from random import random 
import numpy as np 
import matplotlib.pyplot as plt 
from scipy.stats import scoreatpercentile 

x = np.array([random() for x in xrange(100)]) 

# percentiles of interest 
perc = [min(x), scoreatpercentile(x,10), scoreatpercentile(x,25), 
       scoreatpercentile(x,50), scoreatpercentile(x,75), 
       scoreatpercentile(x,90), max(x)] 
midpoint = 0 # time-series time 

fig = plt.figure() 
ax = fig.add_subplot(111) 
# min/max 
ax.broken_barh([(midpoint-.01,.02)], (perc[0], perc[1]-perc[0])) 
ax.broken_barh([(midpoint-.01,.02)], (perc[5], perc[6]-perc[5])) 
# 10/90 
ax.broken_barh([(midpoint-.1,.2)], (perc[1], perc[2]-perc[1])) 
ax.broken_barh([(midpoint-.1,.2)], (perc[4], perc[5]-perc[4])) 
# 25/75 
ax.broken_barh([(midpoint-.4,.8)], (perc[2], perc[3]-perc[2])) 
ax.broken_barh([(midpoint-.4,.8)], (perc[3], perc[4]-perc[3])) 

ax.set_ylim(-0.5,1.5) 
ax.set_xlim(-10,10) 
ax.set_yticks([0,0.5,1]) 
ax.grid(True) 
plt.show() 

Output of the code above

관련 문제