python - 从 matplotlib 箱线图中获取中值
问题描述
我正在使用 matplotlib 生成箱线图。为了创建绘图,箱线图类在内部计算均值、标准差和中位数。如何提取这些数值?
箱线图返回一个字典,其中包含对象。其中包括一个 Line2D 对象列表,位于键“medians”下,数据数组中的每个系列都有一个。
box = ax.boxplot(data, showmeans=True)
box
>>>{'whiskers': [<matplotlib.lines.Line2D at 0x2580149d0d0>,
<matplotlib.lines.Line2D at 0x2580149d460>,
<matplotlib.lines.Line2D at 0x258014a7a00>,
<matplotlib.lines.Line2D at 0x258014a7d90>, ...etc.... ],
'caps': [<matplotlib.lines.Line2D at 0x2580149d7f0>,
<matplotlib.lines.Line2D at 0x2580149db80>,
<matplotlib.lines.Line2D at 0x2580170a160>,
<matplotlib.lines.Line2D at 0x2580170a4f0>, ...etc.... ],
'boxes': [<matplotlib.lines.Line2D at 0x2580410fd00>,
<matplotlib.lines.Line2D at 0x258014a7670>,
<matplotlib.lines.Line2D at 0x2580170afa0>,
<matplotlib.lines.Line2D at 0x25801708910>, ...etc.... ],
'medians': [<matplotlib.lines.Line2D at 0x2580149df10>,
<matplotlib.lines.Line2D at 0x2580170a880>,
<matplotlib.lines.Line2D at 0x258017081f0>,
<matplotlib.lines.Line2D at 0x25802263b20>, ...etc.... ],
'fliers': [],
'means': [<matplotlib.lines.Line2D at 0x258014a72e0>,
<matplotlib.lines.Line2D at 0x2580170ac10>,
<matplotlib.lines.Line2D at 0x25801708580>,
<matplotlib.lines.Line2D at 0x25802263eb0>, ...etc.... ],}
有什么方法可以从绘图对象本身获取中值(也意味着标准偏差)?在某些情况下,这可能很有用,可以将其与我自己根据数据计算的值进行比较。
解决方案
推荐阅读
- vue.js - 如何为 prerender-spa-plgin 正确配置 Vuetify?
- wordpress - 问号在 Wordpress 上不跟随希伯来语中的换行符
- python - 如何生成具有足够间距以容纳大量数字的曲线图
- javascript - 如何修复 TypeError: document.getElementById 在对使用 Leaflet.js 对象的文件运行单元测试时不是一个函数?
- sql - 拥有多封电子邮件的 DAX 用户
- ruby-on-rails - 活动记录的 sum 方法替代方案
- visual-studio-code - 从 VS-Code 添加 NuGet 包时出错
- reactjs - 如何使用“react-google-maps”中的 DrawingManager 重绘多边形
- kubernetes - 上游 k8s 上的 OpenShift Web UI
- sql - 数据库项目 - 设置特定设置 ANSI_NULL_DEFAULT/sp_fulltext_database