Matplotlib boxplot使用预先计算的(摘要)统计信息 [英] Matplotlib boxplot using precalculated (summary) statistics

查看:98
本文介绍了Matplotlib boxplot使用预先计算的(摘要)统计信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要做一个箱线图(在Python和matplotlib中),但是我没有原始的原始"数据. 我所拥有的是最大值,最小值,平均值,中位数和IQR(正态分布)的预先计算的值,但我仍然想做一个箱线图.当然不可能绘制离群值,但是除此之外,我想所有信息都在那里.

I need to do a boxplot (in Python and matplotlib) but I do not have the original "raw" data. What I have are precalculated values for max, min, mean, median and IQR (normal distribution) but still I'd like to do a boxplot. Of course plotting outliers isn't possible, but beside that I guess all information is there.

我一直在搜寻以找到没有成功的答案.我最接近的是相同的问题,但对于R(我不熟悉).参见是否可以绘制从先前计算的统计信息中轻松得出箱形图(在R中)

I've search all over to find an answer without success. The closest I've come is the same question but for R (which I'm unfamiliar with). See Is it possible to plot a boxplot from previously-calculated statistics easily (in R?)

有人可以告诉我如何制作箱线图吗?

Can anyone show me how to do the boxplot?

非常感谢!

推荐答案

在旧版本中,您必须通过分别更改boxplot元素来手动进行操作:

In the old versions, you have to manually do it by changing boxplot elements individually:

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

这篇关于Matplotlib boxplot使用预先计算的(摘要)统计信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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