Python-Matplotlib箱线图。如何显示百分位数0、10、25、50、75、90和100?

7
我想使用Python和Matplotlib绘制EPSgram(见下文)。 boxplot函数只绘制四分位数(0、25、50、75、100)。那么,我该如何添加两个以上的框?

EPSGram boxplot


2
我认为没有简单的方法来做到这一点,但是您可以使用多个broken_barh自己完成。 - aganders3
5
作为一种富有表现力的替代方案,可以考虑使用小提琴图(violin plot)。 - Brian Cain
1个回答

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接