python - 使用 distplot 获取 (x, y) 对 seaborn FacetGrid
问题描述
我正在按照seaborn 文档中的示例绘制一些数据的累积分布:
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
sns.set(style="ticks", color_codes=True)
bins = np.arange(0, 65, 5)
tips = sns.load_dataset("tips")
g = sns.FacetGrid(tips, col="day", height=4, aspect=.5)
g = g.map(sns.distplot, "total_bill", bins=bins, hist_kws={"histtype":"stepfilled"})
现在我想获取与每个 bin 对应的 y 值。我怎样才能做到这一点?
关于 SO(从 Seaborn distplot 获取数据点)的类似问题建议get_data()
从绘图轴线使用。
我试过了
for ax in g.axes[:,0]:
lines = ax.get_lines()
我明白了lines
。<a list of 0 Line2D objects>
这意味着没有可调用的线路get_data()
。
另一个问题(对应于给定 X 值的 Python Seaborn Distplot Y 值)建议使用get_height()
轴补丁。
我试过了
for ax in g.axes[:,0]:
values = [h.get_height() for h in ax.patches]
我得到一个AttributeError: 'Polygon' object has no attribute 'get_height'
. 事实上,我在matplotlib API中看不到任何get_height
方法。Polygon
想法?
更新:
经过一番调查,我发现有论点hist_kws={"histtype":"stepfilled"}
会使通过get_height()
.
解决方案
推荐阅读
- python - 如何在python中比较两个列表的每个元素
- swift - 通过字符串进行类型转换
- javascript - 将参数传递给没有 react-router-dom 中的 url 的路由
- android - 如何设置图像宽度以占用 ConstraintLayout 中的一半空间
- android - 尝试通过 Android 代码设置权重
- laravel - 仅在非 www 上强制 HTTPS
- python - Python - 如何从列表中提取文本
- angular-cli - Angular 6 CLI 未注册服务工作者
- javascript - 如何使用 webgl 和 glMatrix 围绕世界轴旋转对象
- android - AdMob 未显示。没有足够的空间来展示广告(片段文件)