python - histplot 的不同分箱作为 JoinGrid (x,y) 边际图
问题描述
我有一个像这样的熊猫数据框:
日期 | 重量 | 年 | 月 | 天 | 星期 | 星期几 | |
---|---|---|---|---|---|---|---|
0 | 2017-11-13 | 76.1 | 2017 | 11 | 13 | 46 | 0 |
1 | 2017-11-14 | 76.2 | 2017 | 11 | 14 | 46 | 1 |
2 | 2017-11-15 | 76.6 | 2017 | 11 | 15 | 46 | 2 |
3 | 2017-11-16 | 77.1 | 2017 | 11 | 16 | 46 | 3 |
4 | 2017-11-17 | 76.7 | 2017 | 11 | 17 | 46 | 4 |
... | ... | ... | ... | ... | ... | ... | ... |
我创建了一个 JoinGrid:
g = sns.JointGrid(data=df,
x="Date",
y="Weight",
marginal_ticks=True,
height=6,
ratio=2,
space=.05)
然后是定义的联合和边缘图:
g.plot_joint(sns.scatterplot,
hue=df["Year"],
alpha=.4,
legend=True)
g.plot_marginals(sns.histplot,
multiple="stack",
bins=20,
hue=df["Year"])
结果是这样的。
现在的问题是:“是否可以为导致 x 和 y 边缘图的两个 histplot 指定不同的分箱?”
解决方案
我认为没有内置的方法可以做到这一点,您可以使用您选择的绘图功能直接在边缘轴上绘图,如下所示:
penguins = sns.load_dataset('penguins')
data = penguins
x_col = "bill_length_mm"
y_col = "bill_depth_mm"
hue_col = "species"
g = sns.JointGrid(data=data, x=x_col, y=y_col, hue=hue_col)
g.plot_joint(sns.scatterplot)
# top marginal
sns.histplot(data=data, x=x_col, hue=hue_col, bins=5, ax=g.ax_marg_x, legend=False, multiple='stack')
# right marginal
sns.histplot(data=data, y=y_col, hue=hue_col, bins=40, ax=g.ax_marg_y, legend=False, multiple='stack')
推荐阅读
- xero-api - XERO XML 中存在错误 (1,1)
- reinforcement-learning - 深度强化学习中的有效奖励范围
- mysql - 调用 rename() 时 Composer 自我更新错误异常“Permission Denied”
- sql - 每 2 行 SQL 分组
- javascript - 如何在 chrome 扩展中隐藏 Firebase 凭据?
- gps - 重新编程宠物 GPS 跟踪器以将数据发送到我自己的服务器
- ios - Xcode 水平 UIScrollView
- javascript - 使用 firebase 函数 onCall 在 Firestore 中的 CRUD 数据。其中的任何异步操作(Promise)会发生什么?
- java - 在 StringBuffer 中名为 append() 的方法中运行和调试有不同的结果
- javascript - 在 ReactJS 中动态协调 2 下拉菜单