2011-12-30 46 views
7

Tôi muốn vẽ một EPSgram (xem bên dưới) bằng cách sử dụng Python và Matplotlib.Hộp thoại Python-Matplotlib. Làm thế nào để hiển thị phần trăm 0,10,25,50,75,90 và 100?

Chức năng boxplot chỉ lô các phần tư (0, 25, 50, 75, 100). Vì vậy, làm cách nào tôi có thể thêm hai hộp nữa?

EPSGram boxplot

+2

Tôi không nghĩ rằng có một cách dễ dàng để làm điều này, nhưng bạn có thể có thể làm điều đó cho mình sử dụng một số 'broken_barh' . – aganders3

+5

Là một cách thay thế mang tính biểu cảm, hãy xem xét [biểu đồ vĩ cầm] (http://pyinsci.blogspot.com/2009/09/violin-plot-with-matplotlib.html). –

Trả lời

2

Tôi đặt cùng một mẫu, nếu bạn vẫn còn tò mò. Nó sử dụng scipy.stats.scoreatpercentile, nhưng bạn có thể nhận được những con số từ nơi khác:

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

Các vấn đề liên quan