【发布时间】:2018-06-26 05:22:24
【问题描述】:
我必须绘制一些数据的箱线图,这可以通过 Matplotlib 轻松完成。但是,我被要求提供一个表格,其中包含那里提供的数据,例如胡须、中位数、标准差等。
我知道我可以“手动”计算这些,但从参考资料中我也知道boxplot 方法:
Returns a dictionary mapping each component of the boxplot to a list of the matplotlib.lines.Line2D instances created. That dictionary has the following keys (assuming vertical boxplots):
boxes: the main body of the boxplot showing the quartiles and the median’s confidence intervals if enabled.
medians: horizonal lines at the median of each box.
whiskers: the vertical lines extending to the most extreme, n-outlier data points.
caps: the horizontal lines at the ends of the whiskers.
fliers: points representing data that extend beyone the whiskers (outliers).
所以我想知道如何获得这些值,因为它们是 matplotlib.lines.Line2D。
谢谢。
【问题讨论】:
-
“手工”计算这些有什么问题?大多数信息都可以通过
numpy轻松获得,例如与np.median,或np.min和np.max。 -
@BenjaminBannier:特别是对于大型数据集,这是重复工作,因为在创建箱线图时已经调用了更昂贵的函数,例如
median。 -
没错,@jmetz!这些原因我想知道如何从已经计算的箱形图中获取这些值。
-
@pceccon,是的,这是有道理的。
标签: python matplotlib boxplot