在 matplotlib 的 boxplot 函数中改变胡须的末端代表什么 [英] Changing what the ends of whiskers represent in matplotlib's boxplot function

查看:31
本文介绍了在 matplotlib 的 boxplot 函数中改变胡须的末端代表什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解到matplotlib箱形图函数中的晶须末端延伸至最大值低于75%+ 1.5 IQR的最小值,高于25%-1.5 IQR的最小值.我想将其更改为表示数据的最大值和最小值或数据的第 5 和第 95 个四分位数.可以这样做吗?

I understand that the ends of whiskers in matplotlib's box plot function extend to max value below 75% + 1.5 IQR and minimum value above 25% - 1.5 IQR. I would like to change it to represent max and minimum values of the data or the 5th and 95th quartile of the data. Is is possible to do this?

推荐答案

要让胡须出现在数据的最小值和最大值处,请将 whis 参数设置为任意大的数字.换句话说:boxplots = ax.boxplot(myData, whis=np.inf).

To get the whiskers to appear at the min and max of the data, set the whis parameter to an arbitrarily large number. In other words: boxplots = ax.boxplot(myData, whis=np.inf).

whis kwarg是四分位间距的比例因子.胡须被吸引到 whis * IQR 内远离四分位数的最外层数据点.

The whis kwarg is a scaling factor of the interquartile range. Whiskers are drawn to the outermost data points within whis * IQR away from the quartiles.

在matplotlib v1.4中,您可以说: boxplots = ax.boxplot(myData,whis = [5,95])将晶须设置在第5个和第95个百分点.同样,您可以说 boxplots = ax.boxplot(myData, whis='range') 将胡须设置为最小值和最大值.

In matplotlib v1.4, you can say: boxplots = ax.boxplot(myData, whis=[5, 95]) to set the whiskers at the 5th and 95th percentiles. Similarly, you'll be able to say boxplots = ax.boxplot(myData, whis='range') to set the whiskers at the min and max.

注意:您可能可以修改 ax.boxplot 方法返回的 boxplots 词典中包含的艺术家,但这似乎很麻烦

Note: you could probably modify the artists contained in the boxplots dictionary returned by the ax.boxplot method, but that seems like a huge hassle

这篇关于在 matplotlib 的 boxplot 函数中改变胡须的末端代表什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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