You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Seaborn绘制带regplot且边际轴仅显示平滑密度曲线的jointplot?

当然可以实现。你只需要在jointplot中通过marginal_kws参数指定边际轴使用平滑密度曲线(KDE),同时保留kind='reg'来显示回归拟合线。

具体代码示例如下:

import seaborn as sns
import matplotlib.pyplot as plt

# 替换input为你的实际数据集
g = sns.jointplot(data=input, x='age', y='score', kind='reg',
                  marginal_kws={'kind': 'kde', 'fill': True})
plt.show()

代码说明:

  • kind='reg' 保持中心图为回归拟合图(regplot)
  • marginal_kws={'kind': 'kde'} 指定边际轴使用核密度曲线,也就是你要的平滑密度曲线
  • fill=True 可选参数,用来填充密度曲线下方的区域,让图形更清晰,不需要的话可以删除这个参数

内容的提问来源于stack exchange,提问作者ls98

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 18:04:50