Python-Matplotlib箱线图。如何显示百分位数0、10、25、50、75、90和100? [英] Python-Matplotlib boxplot. How to show percentiles 0,10,25,50,75,90 and 100?

查看:363
本文介绍了Python-Matplotlib箱线图。如何显示百分位数0、10、25、50、75、90和100?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想绘制一个,但您可能会从其他地方获取这些数字:

 来自随机导入从scipy.stats随机抽取
numpy作为np
import matplotlib.pyplot as plt
从scipy.stats导入scoreatpercentile

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

#感兴趣的百分位
perc = [min(x),scoreatpercentile(x,10),scoreatpercentile(x,25),
scoreatpercentile(x ,50),scoreatpercentile(x,75),
scoreatpercentile(x,90),max(x)]
中点= 0#时间序列时间

图= plt .figure()
ax = fig.add_subplot(111)
#最小/最大
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],per c [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])$ ​​b $ b ax.grid(True)
plt.show()


I would like to plot an EPSgram (see below) using Python and Matplotlib.

The boxplot function only plots quartiles (0, 25, 50, 75, 100). So, how can I add two more boxes?

解决方案

I put together a sample, if you're still curious. It uses scipy.stats.scoreatpercentile, but you may be getting those numbers from elsewhere:

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()

这篇关于Python-Matplotlib箱线图。如何显示百分位数0、10、25、50、75、90和100?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆